JSHint warns about const and let because it is not told your code is ES6
JSHint warns on const or let and suggests setting esversion: 6Short answer
JSHint only accepts the syntax of the ECMAScript version it is told to check. Without the esversion option, ES6 features such as const trigger a warning. Set esversion to 6 or higher in .jshintrc, in the jshintConfig key of package.json, or in an inline comment.
Fix it fast
1Find out which cause you have
Find which JSHint configuration is actually used for the file. The config file is searched from the file's folder up to the root.
ls -a | grep -i jshint grep -n "jshint" package.json2Match what you see, then jump to its fix
- 1
The warning suggests esversion: 6 as the way outesversion is not setFix - 2
You set esversion but the same warning remainsThe setting is in a place JSHint does not read, or in a file it did not findFix - 3
Config uses esnext, or only one file warnsAn old esnext option is used, or one file needs its own settingFix
- 1
What does the error look like?
JSHint warns on const or let and suggests setting esversion: 6The same file lints clean once esversion is set
Cause 1 of 3
esversion is not set
1Check
The esversion option tells JSHint which ECMAScript version your code uses. No option, no ES6 syntax.
cat .jshintrc2Fix
Add esversion to the config. Use 6 or a higher number your code needs.
// .jshintrc
{
"esversion": 6,
"node": true
}3Verify
Run JSHint on the file.
npx jshint src/index.jsConfirmed by jshint.com
Cause 2 of 3
The setting is in a place JSHint does not read, or in a file it did not find
1Check
JSHint reads .jshintrc from the linted file's folder and then each parent folder up to the root, or a file given with --config. It also reads the jshintConfig key of package.json. Stdin input does not search for .jshintrc.
ls -a . .. | grep jshintrc
grep -n jshintConfig package.json2Fix
Move the option to the config that is read, or pass it explicitly.
npx jshint --config .jshintrc src/index.js3Verify
The warning is gone.
npx jshint --config .jshintrc src/index.js && echo okConfirmed by jshint.com
Cause 3 of 3
An old esnext option is used, or one file needs its own setting
1Check
The options page says esnext is deprecated, to be removed in the next major version, and to use esversion: 6 instead. Options can also be set per file with an inline comment.
grep -rn "esnext" .jshintrc package.json2Fix
Replace esnext with esversion, or add the directive at the top of the single file.
// jshint esversion: 6
const answer = 42;3Verify
Lint the file again.
npx jshint src/index.jsConfirmed by jshint.com
How do I stop it coming back?
- Keep one shared .jshintrc at the project root.
- Set node: true for server code so Node.js globals are known.
- Consider a modern linter if you use newer syntax, since JSHint support follows its esversion setting.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix