简体   繁体   English

babel-eslint 不允许动态导入

[英]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.

相关问题 如何在没有配置文件的情况下修复导入/导出babel-eslint? - How to fix import/export babel-eslint without configuration file? 在 Windows 10 上全局安装 ESLint + babel-eslint 解析器 - Install ESLint + babel-eslint parser globally on Windows 10 在Sublime Text 3上使用babel-eslint时,Linting无法正常工作 - Linting not working when using babel-eslint on Sublime Text 3 使用babel-eslint导致错误的空值错误 - Using babel-eslint caused false no-empty error Create React App 提供的 react-scripts package 需要依赖: "babel-eslint": "^10.1.0" 不要手动安装 - The react-scripts package provided by Create React App requires a dependency: "babel-eslint": "^10.1.0" dont install it manually Eslint 不允许 static class 属性 - Eslint does not allow static class properties 动态import()使用webpack和babel语法错误 - Syntax Error on dynamic import() using webpack and babel 如何告诉eslint允许分阶段的ECMA-Script动态导入 - How to tell eslint to allow staged ECMA-Script dynamic imports 有没有办法让 ESLint 在不添加 Babel 的情况下理解新的导入断言语法? - Is there a way to make ESLint understand the new import assertion syntax without adding Babel? webpack 带eslint laoder的通天塔装载机 - webpack babel loader with eslint laoder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM