Parsing Error The Keyword import is Reserved (SublimeLinter-contrib-eslint)

JavascriptParsingSublimetextEslint

Javascript Problem Overview


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"
  }
}

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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

Solution 3 - Javascript

Spent 30 mins - trying all solutions but dint work, so sharing this one.

The issue is seen with new react app, and in Visual Studio Code, even at this time - Apr 2020.

  1. Create a file .eslintrc.js in the root folder (beside package.json, or beside /src/ directory)
  2. Paste below contents in .eslintrc.js
  3. Restart your editor, like VS Code.
  4. Now I can see real errors, instead of those fake import/export errors.

.eslintrc.js file contents:

module.exports = {
  env: {
	commonjs: true,
	node: true,
	browser: true,
	es6: true,
	jest: true,
  },
  extends: ["eslint:recommended", "plugin:react/recommended"],
  globals: {},
  parser: "babel-eslint",
  parserOptions: {
	ecmaFeatures: {
	  jsx: true,
	},
	ecmaVersion: 2018,
	sourceType: "module",
  },
  plugins: ["react", "import", "react-hooks"],
  ignorePatterns: ["node_modules/"],
  rules: {},
  settings: {
	react: {
	  version: "latest", // "detect" automatically picks the version you have installed.
	},
  },
};

Hope that helps.

Solution 4 - Javascript

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

Solution 5 - Javascript

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

Solution 6 - Javascript

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

Solution 7 - Javascript

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

Solution 8 - Javascript

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

Solution 9 - Javascript

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
    }
  }

Solution 10 - Javascript

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.

Solution 11 - Javascript

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",
       };

Solution 12 - Javascript

Adding ecmaVersion to .eslintrc.json fixed the issue

{
    "ecmaVersion": 2015,
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ]
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpedro luisView Question on Stackoverflow
Solution 1 - JavascriptIman MohamadiView Answer on Stackoverflow
Solution 2 - Javascriptuser8202629View Answer on Stackoverflow
Solution 3 - JavascriptManohar Reddy PoreddyView Answer on Stackoverflow
Solution 4 - Javascriptpedro luisView Answer on Stackoverflow
Solution 5 - JavascriptJulienRiouxView Answer on Stackoverflow
Solution 6 - JavascripttheView Answer on Stackoverflow
Solution 7 - JavascriptCrisoforo GasparView Answer on Stackoverflow
Solution 8 - JavascriptSPMView Answer on Stackoverflow
Solution 9 - JavascriptNitin JadhavView Answer on Stackoverflow
Solution 10 - JavascriptBhupinderView Answer on Stackoverflow
Solution 11 - JavascriptMohammad FashaView Answer on Stackoverflow
Solution 12 - JavascriptGvs AkhilView Answer on Stackoverflow