126

I have a problem with eslint, it gives me [Parsing Error The keyword import is reserve] this is only occur in sublime, in atom editor work well. I have eslint

.eslintrc.js

module.exports = {
    "extends": "airbnb",
    "plugins": [
        "react"
    ]
};

package.json

{
  "name": "paint",
  "version": "0.0.0",
  "description": "paint on the browser",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "paint",
    "javascript"
  ],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browserify": "^11.2.0",
    "eslint": "^2.2.0",
    "eslint-config-airbnb": "^2.1.1",
    "eslint-plugin-react": "^3.11.2",
    "gulp-babel": "^5.2.1",
    "gulp-clean": "^0.3.1",
    "gulp-stylus": "^2.2.0",
    "vinyl-source-stream": "^1.1.0"
  }
}
paulhhowells
  • 321
  • 3
  • 11
pedro luis
  • 1,545
  • 2
  • 10
  • 8

13 Answers13

241

Add this to the root of your .eslintrc.json (formerly .eslintrc)

"parser": "babel-eslint"

and make sure to run:

npm install babel-eslint --save-dev
Henke
  • 4,445
  • 3
  • 31
  • 44
Iman Mohamadi
  • 6,552
  • 3
  • 34
  • 33
97

The eslint option that solves the "The keyword import is reserved" error is parserOptions.sourceType. Setting it to "module" allows the import keyword to be used.

.eslintrc

{
    "parserOptions": {
        "sourceType": "module"
    }
}

Docs: https://eslint.org/docs/user-guide/configuring#specifying-parser-options

nathancahill
  • 10,452
  • 9
  • 51
  • 91
  • 1
    Additionally, although I do not use babel, `npm install babel-eslint --save-dev` and `parser: 'babel-eslint'` were needed to get rid of the 'import is reserved' error. It is [not a good solution](https://github.com/eslint/eslint/issues/11189#issuecomment-446646882) but a workaround [recommended by eslint for now](https://github.com/eslint/eslint/issues/11486). – Akseli Palén Feb 02 '21 at 22:21
  • 5
    Yes, but I also had to add `"ecmaVersion": "latest"` under `parserOptions`. – Michael Cox Dec 15 '22 at 21:44
19

The problem was i had installed eslint globally and locally, causing inconsistencies in SublimeLinter-contrib-eslint. I uninstalled eslint globally and SublimeLinter is working.

pedro luis
  • 1,545
  • 2
  • 10
  • 8
14

Closing VS code and re-open it does the trick for me...

JulienRioux
  • 2,853
  • 2
  • 24
  • 37
7

Not sure about it but try to rename your file to .eslintrc and just use

{
  "extends": "airbnb",
  "plugins": ["react"]
};

Also be sure you have the required packages installed. github.com/airbnb/javascript

the
  • 99
  • 3
7

The accepted answer works, however, is no longer under maintenance and the newly suggested approach is to use the version from the mono repo instead.

Installation

$ npm install eslint @babel/core @babel/eslint-parser --save-dev
# or
$ yarn add eslint @babel/core @babel/eslint-parser -D

.eslintrc.js

module.exports = {
  parser: "@babel/eslint-parser",
};

Reference

Crisoforo Gaspar
  • 3,740
  • 2
  • 21
  • 27
3

i also got this error in a meteor project and i could solved it setting sourceType to "module" more details can be found in Eslint docs: http://eslint.org/docs/user-guide/configuring#specifying-parser-options

SPM
  • 31
  • 3
3

This config worked for me. (I am using create-react-app but applicable to any eslint project)


.eslintrc (create file in root if it doesnt exist)

{
    "rules": {
      "jsx-a11y/anchor-is-valid": [ "error", {
        "components": [ "Link" ],
        "specialLink": [ "to" ]
      }]
    },
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 2015
    }
  }
Nitin Jadhav
  • 6,495
  • 1
  • 46
  • 48
2

The same issue occurred when creating js files within a typescript react-native project while eslint is enabled.

Changing the file type from js to ts resolved the issue.

Also, adding the .eslintrc.js file as mentioned in previous answers resolved the issue without changing the file type from js to ts.

       module.exports = {
          parser: "@babel/eslint-parser",
       };
Mohammad Fasha
  • 188
  • 1
  • 9
2

The issue is seen with the new react app, and in Visual Studio Code, even at this time - August 2022

Create a file .eslintrc.js in the root folder Paste the below contents in .eslintrc.js Restart your editor, like VS Code. Now I can see real errors, instead of those fake import/export errors. .eslintrc.js file contents:

   export const parser = "@babel/eslint-parser";

The accepted answer works, however, the newly suggested approach is to use the version from ES6.

skr
  • 1,700
  • 1
  • 15
  • 39
1

I found this issue while creating the vue project (Used Editor: Visual Code)

Install babel-eslint package

npm install babel-eslint

Create the .eslintrc.js file and add below code

module.exports = {
    root: true,
    parserOptions: {
        'sourceType': 'module',
        parser: 'babel-eslint'   
    }
}

npm run serve, that error will be resolved like magic.

Sreekumar P
  • 5,900
  • 11
  • 57
  • 82
Bhupinder
  • 11
  • 2
  • OR, try without 'sourceType' module.exports = { root: true, parserOptions: { parser: 'babel-eslint' } } – Bhupinder Mar 16 '20 at 01:08
1

Adding ecmaVersion to .eslintrc.json fixed the issue

{
    "ecmaVersion": 2015,
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ]
}
Gvs Akhil
  • 2,165
  • 2
  • 16
  • 33
0

ESlint the disabling rules in .eslintrc.json file.

  {
  "extends": "next",
  "rules": {
    "react/no-unescaped-entities": "off",
    "@next/next/no-page-custom-font": "off"
  }
}
Apurv
  • 21
  • 5