Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...