eslint: Illegal import declaration

Just updated to 0.17.1 and still getting the error: Illegal import declaration on the following line.

import request from 'superagent';

And here is my .eslintrc

{
  "ecmaFeatures": {
    "jsx": true
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "rules": {
    "strict": 0,
    "no-underscore-dangle": 0,
    "quotes": [
      2,
      "single"
    ]
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 29 (17 by maintainers)

Commits related to this issue

Most upvoted comments

this works for me:

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

You need to enable modules via ecmaFeatures: { modules: true }

@brettz9 imports are only valid in the top level scope. Babel allows you to do them in the inner scopes, but that’s incorrect and doesn’t adhere to the es6 spec.

{
    "parser": "babel-eslint",
    "env": {
        "browser": true,
        "node": true,
        "es6": true
    },
    "ecmaFeatures": {
        "modules": true
    },
    "rules": {
    }
}

That’s what I have and I still keep seeing “Illegal import declaration” and “Illegal export declaration” for all of my files. I just installed everything yesterday, so it should be up-to-date. I’ve tried several different ways of doing ES2015 imports and exports (e.g. named vs default exports, etc.), but I’m still getting the errors.

Came here from Google, so in case it helps anyone else, I’ll add that my problem was the parser esprima-fb, when using babel-eslint the error went away.

@Hancoson can you open a new ticket or come by our ESLint Gitter? Thanks!

Babel only allows it with parser option: allowImportExportEverywhere set to true