I'm trying to run npm build
but I get "no-unused-vars" errors. I'd like to disable these.
My project is build with create-react-app (https://github.com/facebook/create-react-app), React + Typescript + Vite.
What I have tried:
tsconfig.json
"compilerOptions": { "noUnusedLocals": false, "noUnusedParameters": false, }
eslint.config.json
"no-unused-vars": [ "error", { caughtErrors: "none" } ],
"@typescript-eslint/no-unused-vars": ["off"]
.eslintrc.js
module.exports = {
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
}
}
package.json
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off"
}
What's the proper way to disable the "no-unused-var" errors in my React project? What should I try other than these solutions that haven't worked for me?
Disclaimer: I am NOT looking to put "_" before variables or suppressing the error with comments.
I expected the project to build without giving me "no-unused-vars" errors.
I solved this by updating the eslint install with npm i eslint
then putting this in eslint.config.js:
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-explicit-any":0,
},
But it only worked after upgrading the version of eslint that create-react-app has installed, for some reason.
As @Phil commented, create-react-app shouldn't be used as it's unmaintained.