Eslint: "error Parsing error: The keyword 'const' is reserved"
โกTLDR
Solve the "Parsing error: The keyword 'const' is reserved" in ESLint following these steps:
- Update
.eslintrcto enable ES6 syntax:
- Make sure your ESLint recognizes ES6. If you're using Babel, install
@babel/eslint-parser:
- Check Node.js version. Outdated Node.js may cause compatibility issues with ES6 features.
Configure ESLint properly
ESLint configuration resides in the .eslintrc file. There we need to specify that we are using modern JavaScript syntax. Here's the game plan:
- Make sure ESLint has version v7.30.0 or up. Latest versions provide full ES6 support.
- Put
/* eslint-env es6 */at the top of your JavaScript files - This is like telling ESLint: "Hey, we're in the ES6 era now!". - Set
"latest"as theecmaVersioninparserOptions. This enables the newest ECMAScript features. - The
envobject should include{ "es6": true }. This gives access to ES6 global objects, like the belovedPromise. - Keep
eslint-pluginandeslint-configup-to-date. Up-to-date devDependencies make for a happy project! ๐ - In Visual Studio Code, use
"eslint.options"insettings.jsonto match your ESLint's behaviour to your coding style.
Advanced: Managing upgrades and potential issues
Upgrades are great, most of the time. Sometimes though, they can introduce new problems. For those situations:
- Run periodic npm package updates. This ensures version compatibility and can resolve issues introduced by previous updates.
- Keep in mind: If
"latest"in theecmaVersioncauses problems, you can set it to2017or the specific version suiting your codebase best.
Remember, using /* eslint-disable */ is akin to chopping off the branch you're sitting on - It's rarely the best solution!
ESLint fine-tuning
ESLint can be fine-tuned to accommodate almost any coding style or project configuration:
- Use additional
parserOptionsin.eslintrc.jsfor custom ESLint behaviour. "useEslintrc": falsein the Visual Studio Codesettings.jsonis an override for project-specific.eslintrc.jsonsettings.- Place ESLint configuration comments at the beginning of the file to ensure they're applied throughout the file.
๎ขLinked
๎ขLinked
Was this article helpful?