Several built-in Nuxt globals are not defined in ESLint config, causing linter to error in JS files
Environment
- Operating System: Darwin
- Node Version: v22.1.0
- Nuxt Version: 3.12.2
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, modules
- Runtime Modules: @nuxt/[email protected]
- Build Modules: -
Package
None
Reproduction
https://github.com/adamreisnz/nuxt-eslint-reproduction/tree/issue-461
Describe the bug
Several built-in Nuxt globals are showing up as undefined, despite using the Nuxt ESLint module. For example, check the files:
nuxt.config.ts --> defineNuxtConfig is marked by ESLint as not defined
server/test.js --> defineEventHandler and readBody are marked by ESLint as not defined
This list is probably non-exhaustive, it's just the methods I've used so far.
Additional context
This is with a brand new Nuxt app with module enabled, and some additional globals
Logs
No response
@adamreisnz Why would you add your own @eslint/js and eslint-plugin-vue configs to override Nuxt's configs?
https://github.com/adamreisnz/nuxt-eslint-reproduction/blob/a32edf5fd06da40dc9cc3b0f8b7fc3b050578cbc/eslint.config.mjs#L6-L7
Why does that matter for this problem?
I don't know what base settings Nuxt uses, and I want to make sure that the base Vue settings that I need are included.
This shouldn't affect global as they don't get overwritten.
On Sat, 29 Jun 2024, 13:03 Anthony Fu, @.***> wrote:
@adamreisnz https://github.com/adamreisnz Why would you add your own @eslint/js and eslint-plugin-vue configs to override Nuxt's configs?
https://github.com/adamreisnz/nuxt-eslint-reproduction/blob/a32edf5fd06da40dc9cc3b0f8b7fc3b050578cbc/eslint.config.mjs#L6-L7
— Reply to this email directly, view it on GitHub https://github.com/nuxt/eslint/issues/461#issuecomment-2197807277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADXYQXZTLQQISOX3APSW2DZJYBXJAVCNFSM6AAAAABKCSJCCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJXHAYDOMRXG4 . You are receiving this because you were mentioned.Message ID: @.***>
I don't know what base settings Nuxt uses, and I want to make sure that the base Vue settings that I need are included.
Use the config inspector to see what is being loaded. Or check the source-code.
I have removed the extra configuration from the eslint.config.mjs file to avoid discussions about it detracting from the problem at hand.
Methods calls like defineEventHandler and readBody are still flagged as not defined in .js files.
The error goes away in the .ts file, because in your config, no-undef has been disabled fully for TS files (see https://github.com/nuxt/eslint/issues/452)
Is there any new about a potential fix for this?
I added globals to my eslint config, but yeah I think it should auto detect all nitro imports by default, not sure why it doesn't
import stylistic from '@stylistic/eslint-plugin'
import withNuxt from './.nuxt/eslint.config.mjs'
export default withNuxt(
{
plugins: {
'@stylistic': stylistic,
},
rules: {
'vue/multi-word-component-names': 'off',
},
languageOptions: {
globals: {
defineEventHandler: true,
getBody: true
}
}
},
)