[英]babel-eslint does not allow dynamic import
I use webpack 2 and I want to make dynamic import.我使用 webpack 2 并且我想进行动态导入。 Linter gives the following error on dynamic import (that is
import(...)
): Linter 在动态导入(即
import(...)
)时出现以下错误:
[js] Declaration or statement expected.
[js] 预期的声明或声明。 (JSX attribute) import: true.
(JSX 属性)导入:true。
I have following .eslintrc
(excerpt):我有以下
.eslintrc
(摘录):
{
"parser": "babel-eslint",
"parserOptions": {
"allowImportExportEverywhere": true
}
}
Following is installed:安装如下:
"eslint": "^3.16.1",
"babel-eslint": "^7.2.3",
"babel-plugin-dynamic-import-webpack": "^1.0.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
babelrc configuration: babelrc 配置:
{
"presets": [
"es2015",
"react"
],
"plugins": ["syntax-dynamic-import", "dynamic-import-webpack"]
}
Update: Example where error occurs (react app).更新:发生错误的示例(反应应用程序)。 (Here the error is just
[js] Declaration or statement expected
): (这里的错误只是
[js] Declaration or statement expected
):
const App = () => {
import('./routes/Main/Main').then((Main) => {});
return(<div />);
};
I found the reason why this happens.我找到了发生这种情况的原因。
It seems VSCode has internal javascript linter that is enabled even if eslint plugin is linting.即使 eslint 插件正在 linting,VSCode 似乎也启用了内部 javascript linter。 Disabling this internal linter solves the issue.
禁用这个内部 linter 可以解决这个问题。 So to solve, in project (
.vscode/settings.json
), user or global VSCode settings set the following:所以要解决,在项目(
.vscode/settings.json
)中,用户或全局 VSCode 设置设置如下:
{
...other settings...,
"javascript.validate.enable": false
}
Adding the following to the .eslintrc.js file solved it for me:将以下内容添加到 .eslintrc.js 文件为我解决了这个问题:
settings: {
'import/resolver': {
node: {
paths: [path.resolve(__dirname, 'src')],
},
},
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.