ignore eslint error: 'import' and 'export' may only appear at the top level

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 14:27:00

问题


Is it possible to deactivate this error in eslint?

Parsing error: 'import' and 'export' may only appear at the top level

回答1:


ESLint natively doesnt support this because this is against the spec. But if you use babel-eslint parser then inside your eslint config file you can do this:

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": true
  }
}

Doc ref: https://github.com/babel/babel-eslint#configuration




回答2:


my solution incase other dont work

"parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
}



回答3:


Support for dynamic import has been added in eslint 6.2.

You need to set ecmaVersion to 11 (or 2020) though.

"parserOptions": {
    "ecmaVersion": 11
    ...
}

You can test that in their online demo.



来源:https://stackoverflow.com/questions/39158552/ignore-eslint-error-import-and-export-may-only-appear-at-the-top-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!