使用 Atom编辑,与linter-eslint安装包后,我有一个使用 ES6 模块的 import 的 node.mjs 脚本导入各种 Node 模块的语句。
当我使用 Node 的 --experimental-modules 运行脚本时,脚本运行良好旗帜。然而,在使用 Atom 进行编辑时,linter-eslint 说:
Parsing error: Unexpected token import (Fatal)
此解析错误不是是由我在代码文件顶部的 ecmascript“导入”语句引起的。相反,它实际上是由于 eslint 认为“导入”一个只能在 import statements 中使用的保留 token 。因此不能被 import.meta 使用对象(如下面的代码行所示):
const __dirname = path.dirname(new URL(import.meta.url).pathname);
我的 .eslintrc.js 文件有这些解析器选项:
'parserOptions':
{
'ecmaVersion': 2018,
'sourceType': 'module'
}
如何配置 eslint 以忽略此特定错误?
最佳答案
我也遇到了这个问题。在 eslint 7.2.0 中添加了对 import.meta
的支持(2020 年 6 月)但是为了让它工作,我必须编辑 .eslintrc.json
并将 ecmaVersion
从 2018
更改为 2020
。
关于javascript - ESlint - import.meta 导致致命解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54337576/