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.

AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context

See original GitHub issue

“version”: “1.8.0” “escope”: “^3.2.0”

This issue is coming from escope in general (feel free to redirect there instead), though not sure which config option in eslint exists to enable modules mode (other than ecmaFeatures: { modules: true } which we already use).

We use ESLintTester (which seems is deprecated now, so maybe issue can be related as well). Trying to test the:

import Foo from 'Foo';

// Or type

import type Bar from 'Bar';

Fails with the assertion in the escope:

- AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.
        at Referencer.ImportDeclaration (scripts/lint/eslint/node_modules/eslint/node_modules/escope/lib/referencer.js:711:17)
        at Referencer.Visitor.visit (scripts/lint/eslint/node_modules/eslint/node_modules/escope/node_modules/esrecurse/esrecurse.js:109:34)
        at Referencer.Visitor.visitChildren (scripts/lint/eslint/node_modules/eslint/node_modules/escope/node_modules/esrecurse/esrecurse.js:88:38)
        at Referencer.Program (scripts/lint/eslint/node_modules/eslint/node_modules/escope/lib/referencer.js:539:22)
        at Referencer.Visitor.visit (scripts/lint/eslint/node_modules/eslint/node_modules/escope/node_modules/esrecurse/esrecurse.js:109:34)
        at Object.analyze (scripts/lint/eslint/node_modules/eslint/node_modules/escope/lib/index.js:130:16)
        at EventEmitter.module.exports.api.verify (scripts/lint/eslint/node_modules/eslint/lib/eslint.js:736:35)
        at runRuleForItem (scripts/lint/eslint/node_modules/eslint/lib/testers/rule-tester.js:265:34)
        at testInvalidTemplate (scripts/lint/eslint/node_modules/eslint/lib/testers/rule-tester.js:302:26)
        at Spec.<anonymous> (scripts/lint/eslint/node_modules/eslint/lib/testers/rule-tester.js:370:21)

Is it a known issue? I didn’t find other config options to allow import in the tests.

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

50reactions
gasolincommented, Mar 16, 2016

I follow doc to add following options in .eslintrc.json file, and the issue is gone

  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "modules": true
    }
  }
5reactions
katwal-dipakcommented, Aug 30, 2017

https://eslint.org/docs/user-guide/configuring#specifying-parser-options

adding the following lines in .eslintrc fixed the issue in my side.

"parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Atom & eslint update : ImportDeclaration should appear when ...
But now, I have got an error on eslint check : AssertionError: ImportDeclaration should appear when the mode is ES6 and in the...
Read more >
Parsing error: ImportDeclaration should appear when the ...
Appears to be a problem with the babel eslint package but cant quite figure ... should appear when the mode is ES6 and...
Read more >
importdeclaration should appear when the mode is es6 and in ...
Line 0: Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context. Luckily, I have already posted a...
Read more >
"Parsing error: ImportDeclaration should appear ... - Issuehunt
"Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context." in update to 0.45.0 #615. muziejus posted onGitHub....
Read more >
eslint-config-light - npm Package Health Analysis - Snyk
AssertionError : ImportDeclaration should appear when the mode is ES6 and in the module context.
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