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

前端 未结 3 970
-上瘾入骨i
-上瘾入骨i 2020-12-01 15:50

Is it possible to deactivate this error in eslint?

Parsing error: \'import\' and \'export\' may only appear at the top level
相关标签:
3条回答
  • 2020-12-01 16:16

    my solution incase other dont work

    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module"
    }
    
    0 讨论(0)
  • 2020-12-01 16:23

    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.

    0 讨论(0)
  • 2020-12-01 16:36

    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

    0 讨论(0)
提交回复
热议问题