简体   繁体   中英

How to specify parser with ESLint? Parsing error: Unexpected token, expected “;”

My eslinter.json

{
    "env": {
        "browser": true,
        "es2020": true
    },
    "parser": "babel-eslint",
    "extends": [
        "plugin:react/recommended",
        "airbnb"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}

When I run

eslint .eslintrc.json

I have parsing error

  2:10  error  Parsing error: Unexpected token, expected ";"

  1 | {
> 2 |     "env": {
    |          ^
  3 |         "browser": true,
  4 |         "es2020": true
  5 |     },

✖ 1 problem (1 error, 0 warnings)

I have added babel-eslint parser. The same. It seems that errors are caused by incompatibilities in my parser options and the code I am writing(Ubuntu + VSCode).

How to fix this?

The error is because you are telling eslint to lint the JavaScript in the .eslintrc.json file … and the file contains JSON, not JavaScript.

If you want to override the normal process for locating the config file, you can use eslint --config your.js but that shouldn't be needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM