Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat config mode not detected when config is outside of root #338

Closed
GaborTorma opened this issue Mar 19, 2024 · 9 comments
Closed

Flat config mode not detected when config is outside of root #338

GaborTorma opened this issue Mar 19, 2024 · 9 comments

Comments

@GaborTorma
Copy link

GaborTorma commented Mar 19, 2024

I tried a new 0.3.0.alpha.0 and alpha.1 version in WSL Debian and checker: true.
I'v got the following error if I try to run it in VS Code JS Debugger terminal. In bash, we have no error.

[3:42:59 PM]  ERROR  [uncaughtException] Cannot read properties of undefined (reading 'lintFiles')

  at lintFiles (node_modules/.pnpm/vite-plugin-eslint2@4.4.0_@types+eslint@8.56.6_eslint@8.57.0_rollup@4.13.0_vite@5.1.6/node_modules/vite-plugin-eslint2/dist/shared/vite-plugin-eslint2.7280f04e.mjs:232:119)
  at MessagePort.<anonymous> (node_modules/.pnpm/vite-plugin-eslint2@4.4.0_@types+eslint@8.56.6_eslint@8.57.0_rollup@4.13.0_vite@5.1.6/node_modules/vite-plugin-eslint2/dist/worker.mjs:38:3)
@antfu
Copy link
Member

antfu commented Mar 19, 2024

Can you help narrow it down to a minimal reproduction? Thank you.

@GaborTorma
Copy link
Author

GaborTorma commented Mar 19, 2024

You can test with this repo: https://github.com/GaborTorma/nuxt-eslint-vs-code-js-debug-terminal-error2
The error messages shows only when the nuxt.config.ts aren't same folder with eslint.config.js like nuxt module development playground.

You need to clone it and start with VS Code and run pnpm i
If you run pnpm dev in bash -> no error
If you run pnpm dev in VS Code JS Debugger terminal -> got error.

I found the problem. When we use in JS Debugger terminal the eslint path is 'eslint', in bash 'eslint/use-at-your-own-risk'.
With 'eslint/use-at-your-own-risk' works well.

@GaborTorma
Copy link
Author

workaround with nuxt.config.ts:

export default defineNuxtConfig({
  modules: [
    '@nuxt/eslint',
  ],

  eslint: {
    checker: {
      eslintPath: 'eslint/use-at-your-own-risk'
    },
  },
})

@antfu
Copy link
Member

antfu commented Mar 20, 2024

Ah I see, we detect flat config under rootDir:

options.configType ||= (process.env.ESLINT_USE_FLAT_CONFIG || flatConfigFiles.some(file => existsSync(resolve(nuxt.options.rootDir, file))))
? 'flat'

I guess, in a way, you have to use that workaround if your config is outside of your root. Or you may do

  eslint: {
    checker: {
      configType: 'flat'
    },
  },

@antfu antfu changed the title ERROR [uncaughtException] Cannot read properties of undefined (reading 'lintFiles') Flat config mode not detected when config is outside of root Mar 21, 2024
@antfu
Copy link
Member

antfu commented Apr 3, 2024

When ESLint v9.0 comes up I think we should then make the default to flat so this won't be an issue later on.

@antfu
Copy link
Member

antfu commented Apr 10, 2024

d84af6f should fix it.

@antfu antfu closed this as completed Apr 10, 2024
@Bredansky
Copy link

Bredansky commented Jul 8, 2024

For some reason, I am still experiencing this error. It doesn't affect anything, but looks annoying :)

nuxt.config.ts:

  eslint: {
    config: {
      stylistic: true,
    },
    checker: true,
  },

package.json:

  "@nuxt/eslint": "^0.3.13",
  "eslint-plugin-tailwindcss": "^3.17.4",
  "vite-plugin-eslint2": "^4.4.0",
  "nuxt": "^3.12.1",

eslint.config.mjs:

import tailwind from 'eslint-plugin-tailwindcss'
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt(
  ...tailwind.configs['flat/recommended'],
  {
    rules: {
      'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
    },
  },
).prepend({
  ignores: ['types'],
})

@GaborTorma
Copy link
Author

This issue is still here if not set the configType to flat.

@AlvesJorge
Copy link

AlvesJorge commented Sep 22, 2024

I think my issue is similar.
My nuxt generated types and eslint.config is only loaded once I visit any file in the .nuxt folder at least once per vscode session.
And by loaded I mean the intellisense starts working :)
Before opening the file
image
After opening any file in the .nuxt folder vscode shows "initialising js/ts"
and the type is now correctly shown
image

With

"@nuxt/eslint": "^0.5.7"
"eslint": "^9.10"

And my rootDir eslint.config.mjs being:

import withNuxt from "./.nuxt/eslint.config.mjs";

export default withNuxt([
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants