Chatie / eslint-config

ESLint Sharable Rules in TypeScript for Chatie Standard Style
https://npmjs.com/package/@chatie/eslint-config
Apache License 2.0
1 stars 0 forks source link

eslint error 'NodeJS' is not defined no-undef #45

Open huan opened 3 years ago

huan commented 3 years ago

@typescript-eslint/parser@4 cause this problem. (related commit: https://github.com/Chatie/eslint-config/commit/4d7265a5b70de8b6f164b602c86969256e30762e)

Downgrade it to v3 @typescript-eslint/parser@3 to solve the problem.

See: https://stackoverflow.com/q/64089216/1123955

huan commented 3 years ago

Monitor this problem to see when the upstream will fix it. (or other solutions)

leolivier commented 3 years ago

Hi, still no solution for that bug? I'm in 4.28.2 and still the issue is here... I'd rather not downgrade to v3

huan commented 3 years ago

Unfortunately, I'm still working with v3 for all my projects...

Please let me know if you have any solutions, thanks and good luck!

abarke commented 3 years ago

I also upgraded to @typescript-eslint/parser@4.28.4

Work around for me was just to add it as a global in .eslintrc.js:

"globals": {
  "NodeJS": true
},
leolivier commented 3 years ago

Thanks @abarke, I will try this. Meanwhile I just added an eslint "no check" comment inside my code for this declaration and it worked.

leolivier commented 3 years ago

I confirm your trick is working for too @abarke, thanks!

thany commented 2 years ago

Workaround is working. But since .eslintrc doesn't allow comments, I cannot link this issue in there in a comment, allowing me to keep track of why that global is there.

I suppose my project will have that workaround years after the issue has been fixed, because I will not be remembering each and every workaround, and their corresponding issue number, by heart...

So I guess it's really important to get this problem fixed sooner rather than later, especially seeing how old it already is. Or release a fix that allows comments. But I prefer the former over the latter, tbh.

ITenthusiasm commented 2 years ago

@thany Strangely enough, if you name files under .eslintrc.json (instead of .eslintrc), you can add comments to the file.

il3ven commented 2 years ago

A proper solution will be to turn off no-undef rule for typescript files. We need this rule for js not ts. This makes sense as typescript handles undefined variables. The project will not build if there are undefined variables. Add the following to your config:

overrides: [
  {
    files: ['*.ts'],
    rules: {
      'no-undef': 'off'
    }
  }
]

This is the recommended method by TypeScript ESLint. See here: https://typescript-eslint.io/docs/linting/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors

Sahillather002 commented 1 year ago

export const cryptoApi=createApi({ reducerPath:'cryptoApi', baseQuery:fetchBaseQuery({baseUrl}), endpoints:(builder)=({ getCrypto:builder.query({ query:()=>createRequest('/coins') }) }) });

Error: ERROR in [eslint] src\services\cryptoApi.js Line 17:16: 'builder' is not defined no-undef
Line 18:19: 'builder' is not defined no-undef

miluoshi commented 5 months ago

This is the answer: https://typescript-eslint.io/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors

Don't use no-undef in TypeScript files/projects