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.

Cannot read property 'ecmaFeatures' of undefined

See original GitHub issue

Getting

Parsing error: Cannot read property 'ecmaFeatures' of undefined

Tell us about your environment

  • ESLint Version: 5.1.0
  • Node Version: 10.6.0
  • **npm Version:**6.1.0"

my eslintrc

env:
  node: true
  es6: true
  jquery: false
  browser: false

extends:
  - eslint:recommended

rules:
  curly: off

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

9reactions
not-an-aardvarkcommented, Aug 1, 2018

The root cause of this issue is that two different versions of espree are being loaded simultaneously with the same version of acorn. espree works by adding a plugin to the acorn parser, and acorn’s plugin API seems to require setting global state on the acorn object. As a result, espree@4 is setting some state by adding listeners to acorn, and then espree@3 is getting loaded and is overriding the state that was set by espree@4. This is causing espree@3’s listeners to unexpectedly get called even though the running version of ESLint is using espree@4, which is causing espree@3 to throw an error.

To me, it seems like the best way to fix this would be for acorn to allow registering a plugin without modifying global state on the acorn package. Another possibility would be for espree to include acorn as a bundled dependency to ensure that it never shares its version of acorn with any other packages.

2reactions
regsebcommented, Jul 31, 2018

@not-an-aardvark This bug comes when eslint@5 and eslint@4 are used in project. It’s not specific at standard (https://github.com/xojs/xo/issues/336 and https://github.com/javascript-obfuscator/webpack-obfuscator/issues/35).

A test case with only ESLint:

  • package.json:
{
    "dependencies": {
        "eslint": "5.2.0",
        "other": "file:./other"
    }
}
  • testcase.js:
#!/usr/bin/env node

var Linter = require("eslint").Linter;
require("other"); // Comment me !
var linter = new Linter();

var messages = linter.verify("var foo;", {
    rules: {
        semi: 2
    }
}, { filename: "foo.js" });

console.log(messages);
  • other/package.json:
{
    "name": "other",
    "main": "index",
    "dependencies": {
        "eslint": "4.19.1"
    }
}
  • other/index.js:
require("eslint");

To test, decompress testcase.tar.gz. Execute npm install and ./testcase.js. This JSON is displayed in console:

[ { ruleId: null,
    fatal: true,
    severity: 2,
    message:
     'Parsing error: Cannot read property \'ecmaFeatures\' of undefined',
    line: undefined,
    column: undefined } ]

If you comment line 4 of testcase.js (require("other");), the output is:

[]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while running ESlint: Cannot read property file
I have the following error in the line of "import React" in each file. import React, { Component } from 'react'. The error...
Read more >
parsing error: cannot read properties of undefined ... - You.com
I'm getting error Parsing error: Cannot read properties of undefined (reading 'map') on this line in my module file: import { StoreLocation, Location...
Read more >
eslint/eslint - Gitter
It is look like the issue in the npm script, but I can't understand where is it. ... This error "Cannot read property...
Read more >
@justeat/gulp-build-fozzie - npm
... Parsing error: Cannot read property 'ecmaFeatures' of undefined . ... Each of these tasks copies the specified set of assets from the ......
Read more >
Supressing ESLint LS errors - Language Server Protocol (LSP)
ESLint : Cannot read properties of undefined (reading 'loc') Occurred while linting /home/non/test/index.ts. Please see the 'ESLint' output ...
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