Node.js and eslint disagree with "use strict"

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

However, when I run node index.js I node index.js "SyntaxError: [let] is not supported in strict mode." works with the "redundant" "use strict" pragma.

Why inconsistency? Should node know that this node module is really strict by default? Could this be caused by some simple wrong node, ESLint or my IDE configuration?

+5
source share
1 answer

ESLint makes its own decisions about what it considers to be valid or invalid warnings or errors. You should relate to everything that eslint / jslint / jshint says as a recommendation in addition to everything else. According to someone, their suggestions are optimal and perfectly true.

However, you have some options to suppress this particular warning:

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

The specific reason why you get this warning is because the default interpreter node in its current form is not fully prepared for ES6. For example, in node 4, you cannot use let outside strict mode, even if let is the ES6 keyword.

+9
source

Source: https://habr.com/ru/post/1232322/


All Articles