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.

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

See original GitHub issue

I’m using @typescript-eslint/parser in eslint for tsx files. I have this code in .tsx file:

import React from 'react';

export class Wallboard extends React.Component<{ meetupGroups: [string] }> {
  constructor(props: Readonly<{ meetupGroups: [string] }>) {
    super(props);
  }

  render(): React.ReactElement {
    return <div>{'ksi'}</div>;
  }
}

and this configuration (+ big webpack configuration):

{
  "parser": "babel-eslint",
  "extends": [
    "@jetbrains",
    "@jetbrains/eslint-config/browser",
    "@jetbrains/eslint-config/es6",
    "@jetbrains/eslint-config/node",
    "@jetbrains/eslint-config/react",
    "@jetbrains/eslint-config/angular",
    "@jetbrains/eslint-config/test"
  ],

  "overrides": [
    {
      "files": ["**/*.ts", "**/*.tsx"],
      "parser": "@typescript-eslint/parser",
      "plugins": ["@typescript-eslint"],
      "extends": [
        "@jetbrains",
        "@jetbrains/eslint-config/browser",
        "@jetbrains/eslint-config/es6",
        "@jetbrains/eslint-config/node",
        "@jetbrains/eslint-config/react",
        "@jetbrains/eslint-config/angular",
        "@jetbrains/eslint-config/test"
      ],
      "settings": {
        "import/resolver": {
          "node": {
            "extensions": [".js",".jsx",".ts",".tsx"]
          }
        }
      }
    }
  ]
}

and I get this error:

/Users/psuwala/projects/hs3/event-monitor/src/components/Wallboard.tsx 0:0 error Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context

I pinpointed that it comes from here:

https://github.com/eslint/eslint-scope/blame/dbddf14d5771b21b5da704213e4508c660ca1c64/lib/referencer.js#L577

of course if I remove this.scopeManager.isModule() it will work.

Any idea if it is possible to override it? Or is it typescript-eslint misuse?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

28reactions
noahehallcommented, Oct 4, 2021

for anyone else following https://json.schemastore.org/eslintrc.json

dont use ecmaVersion: latest

use ecmaVersion: 12 or something else

3reactions
kaicataldocommented, Feb 17, 2020

Apologies for the lack of clarity about having to put this config in parserOptions -what you did is what I was suggesting (ESLint accepts 2015 or 6). 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportDeclaration should appear when the mode is ES6 and ...
This issue is coming from escope in general (feel free to redirect there instead), though not sure which config option in eslint exists...
Read more >
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 >
"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 parsing error: importdeclaration should appear when the ...
Atom & eslint update : ImportDeclaration should appear when the mode is ES6 and in the module context. Asked Mar 12, 2016 •...
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