是否可以在 eslint 中停用此错误?
Parsing error: 'import' and 'export' may only appear at the top level
ESLint 本身不支持这一点,因为这违反了规范。但是如果你使用
babel-eslint
解析器,那么在你的 eslint 配置文件中你可以这样做:
{
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
}
}
我的解决方案,以防其他不起作用
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
}
eslint 6.2添加了对动态导入的支持。
您需要将 ecmaVersion 设置为 11(或 2020)。
"parserOptions": {
"ecmaVersion": 11
...
}
您可以在他们的在线演示中进行测试。
就我而言:
为 React 项目添加了 javascriptreact。我想应该将项目类型添加到插件中。
{
...,
"plugins": [
"prettier",
"javascriptreact"
],
...
}
将其添加到您的 eslint 文件中:
env: {
browser: true,
commonjs: true,
module: true,
es2021: true,
node: true,
},