Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESlint - import.meta causes Fatal Parsing Error

Using the Atom editor, with the linter-eslint package installed, I have a node.mjs script that uses ES6 module's import statement to import various node modules.

The script runs fine when I run it with node's --experimental-modules flag. However, while editing with Atom, linter-eslint says:

Parsing error: Unexpected token import (Fatal)

This parsing error is NOT being caused by the ecmascript "import" statements that I have at the top of my code file. Instead, it is actually caused by the fact that eslint considers "import" a reserved token that can only be used in import statements and therefore cannot be used by the import.meta object (as shown in this code line below):

const __dirname = path.dirname(new URL(import.meta.url).pathname);

My .eslintrc.js file has these parser options:

'parserOptions':
{
    'ecmaVersion': 2018,
    'sourceType': 'module'
}

How can I configure eslint to ignore this particular error?

like image 886
Lonnie Best Avatar asked Jan 24 '19 00:01

Lonnie Best


People also ask

Can ESLint run on code with import ()?

ESLint generally doesn't support syntax features until they reach stage 4 and become official. To run ESLint on code with import (), I would recommend using the babel-eslint parser instead.

How do I fix ESLint parsing error in Visual Studio Code?

Visual Studio Code: Fixing ESLint says “Parsing error: The keyword ‘let’ is reserved.”. If you install the esline plugin in Visual Studio Code, you get weird errors: ESLint says "Parsing error: The keyword 'let' is reserved.". To fix this, you need to set up a config file in the root of your project. You can do this by running: ...

How do I fix ESLint error'let'is reserved?

If you install the esline plugin in Visual Studio Code, you get weird errors: ESLint says "Parsing error: The keyword 'let' is reserved." To fix this, you need to set up a config file in the root of your project. You can do this by running: Here is an example file you can also use:

How do I fix ESLint says “parsing error the keyword is reserved”?

Visual Studio Code: Fixing ESLint says “Parsing error: The keyword ‘let’ is reserved.” If you install the esline plugin in Visual Studio Code, you get weird errors: ESLint says "Parsing error: The keyword 'let' is reserved." To fix this, you need to set up a config file in the root of your project. You can do this by running:


1 Answers

I just came across this issue too. Support for import.meta was added in eslint 7.2.0 (June 2020) however in order to make it work I had to edit .eslintrc.json and change ecmaVersion from 2018 to 2020.

like image 170
Malvineous Avatar answered Oct 27 '22 14:10

Malvineous