Open huan opened 3 years ago
Monitor this problem to see when the upstream will fix it. (or other solutions)
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
Unfortunately, I'm still working with v3 for all my projects...
Please let me know if you have any solutions, thanks and good luck!
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
},
Thanks @abarke, I will try this. Meanwhile I just added an eslint "no check" comment inside my code for this declaration and it worked.
I confirm your trick is working for too @abarke, thanks!
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.
@thany Strangely enough, if you name files under .eslintrc.json
(instead of .eslintrc
), you can add comments to the file.
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
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
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
@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