Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

JSHint warns about const and let because it is not told your code is ES6

ErrorJSHint warns on const or let and suggests setting esversion: 6

Short 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.

  • Applies to JSHint 2.x, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.json
  2. 2Match what you see, then jump to its fix

    1. 1The warning suggests esversion: 6 as the way outesversion is not setFix
    2. 2You 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. 3Config uses esnext, or only one file warnsAn old esnext option is used, or one file needs its own settingFix

What does the error look like?

  • JSHint warns on const or let and suggests setting esversion: 6
  • The 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 .jshintrc

2Fix

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.js

Confirmed by jshint.com

Did this fix it?

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.json

2Fix

Move the option to the config that is read, or pass it explicitly.

npx jshint --config .jshintrc src/index.js

3Verify

The warning is gone.

npx jshint --config .jshintrc src/index.js && echo ok

Confirmed by jshint.com

Did this fix it?

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.json

2Fix

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.js

Confirmed by jshint.com

Did this fix it?

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.