10

ESLint tells me that I do not need "use strict" at the top of my index.js file (it's a simple server like the 6-line one on https://nodejs.org/en/about/). Apparently all node modules are already in strict mode. Makes sense.

However, running node index.js gets me a "SyntaxError: [let] not supported outside strict mode." does run with the "redundant" "use strict" pragma.

Why the inconsistency? Shouldn't node know that this node module is indeed strict by default? Could this be due to some simple misconfiguration of node, ESLint, or my IDE?

ivanjonas
  • 599
  • 7
  • 19

1 Answers1

11

ESLint makes its own decisions about what it considers to be valid or invalid warnings or errors. You have to treat everything that eslint/jslint/jshint says as advisory on top of everything else. According to someone somewhere their suggestions are optimal and perfectly valid.

That being said, you do have some options to suppress this specific warning:

  • Use eslint flags in comments in the code
  • Run eslint with configuration to specify this flag
  • Use the --use-strict flag when running node

The specific reason about why you get this warning has to do with the fact that the default node interpreter as it stands is not fully ES6-ready. For example, in node 4 you cannot use let outside of strict mode even though let is an ES6 keyword.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • 2
    Found official documentation of this at https://nodejs.org/en/docs/es6/ and https://groups.google.com/forum/#!topic/v8-users/3UXNCkAU8Es. Basically, node currently requires strict mode for ES6 block scoping features (`let`, `const`) for backward compatibility reasons. Some time in the future, the --use-strict flag won't be required for `let`. It's a transitory annoyance, which makes it more bearable. – ivanjonas Oct 02 '15 at 17:03