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

江枫思渺然 提交于 2020-03-17 04:07:46

问题


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

回答1:


Add this to the root of your .eslintrc

"parser": "babel-eslint"

and make sure to run:

npm i babel-eslint --save-dev



回答2:


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




回答3:


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




回答4:


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




回答5:


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




回答6:


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



回答7:


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.



来源:https://stackoverflow.com/questions/36002226/parsing-error-the-keyword-import-is-reserved-sublimelinter-contrib-eslint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!