是否有可能在eslint中禁用此错误?
Parsing error: 'import' and 'export' may only appear at the top level
是否有可能在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
...
}
你可以在他们的
sourceType: script
是有效的。 - Luizgrs{
...,
"plugins": [
"prettier",
"javascriptreact"
],
...
}