question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False negatives with sourceType: module and ecmaVersion <= 5

See original GitHub issue

Tell us about your environment

  • ESLint Version: v4.12.1
  • Node Version: 8.4.0
  • npm Version: 5.3.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
module.exports = {
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 5,
    }
}

Running against this file, ecmaVersion is ignored (could also be ‘3’):

// es6.js
const x = () => `hi`;

What did you expect to happen?

Either, I would see an error like the below, rejecting an unsupported config:

> eslint -c withoutModule.config.js es6.js
Incompatible config: sourceType: module cannot be used with ecmaVersion <= 5

or the (admittedly niche*) use-case of ES6 modules with ES5 syntax would be supported, and I’d see errors:

> eslint -c withoutModule.config.js es6.js
es6.js
  1:1  error  Parsing error: The keyword 'const' is reserved

✖ 1 problem (1 error, 0 warnings)

which I get correctly with this config:

// withoutModule.config.js
module.exports = {
    "parserOptions": {
        "ecmaVersion": 5,
    }
}

*niche: I was using rollup with some old ES5 code, and only wanted to modify the code to add imports. I tried the above, and thought “cool, it’s working”, but actually it was silently ignoring the ecmaVersion.

What actually happened? Please include the actual, raw output from ESLint.

No errors are reported:

> eslint es6.js
> echo $?
0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
lapo-luchinicommented, May 2, 2018

Using WebPack it’s possible to use ES6 modules without “really” using them in the output, so checking againt ES5 (or even ES3) would make sense.

1reaction
not-an-aardvarkcommented, Apr 2, 2019

It might be a good idea to do a major (pre)release of espree and update to that version in ESLint before we close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint Parsing error: ecmaVersion must be 3, 5, 6, or 7
I'm setting the ecmaVersion to 8 (per the documentation), but getting this error: Parsing error: ecmaVersion must be 3, 5, 6, or 7....
Read more >
eslint/eslint - Gitter
sourceType can only have 2 values, script or module . ... if the JSON itself is invalid but is valid JS, there would...
Read more >
acorn.mjs - Communardo
ecmaVersion : 10, // `sourceType` indicates the mode the code should be parsed in. ... By default, reserved words are only enforced if...
Read more >
Eslint-plugin-svelte3 NPM | npm.io
Specifically, checks in the context of reactive assignments and store subscriptions will report false positives or false negatives, depending on the rule.
Read more >
How to make ESLint work with Prettier avoiding conflicts and ...
To check syntax, find problems, and enforce code style ... parserOptions: { ecmaVersion: 12, sourceType: 'module', }, rules: { }, };.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found