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

user3142695 picture user3142695 · Aug 26, 2016 · Viewed 34.1k times · Source

Is it possible to deactivate this error in eslint?

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

Answer

Gyandeep picture Gyandeep · Aug 26, 2016

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