Richard Rublev
Richard Rublev

Reputation: 8170

What is wrong with my eslintrc parser options? SyntaxError: Unexpected token ':'

{
    "parserOptions" : {
        "ecmaVersion": 2017
    },

    "env": {
      "browser": true,
      "node": true,
      "es6": true
    },
   }

module.exports = { "extends": "plugin:prettier/recommended" }; 

When I try

eslint test.js

I got this error

/home/miki/azatmardan/ch8/new-restexpress/.eslintrc.js:2
    "parserOptions" : {
                    ^

SyntaxError: Unexpected token ':'

This enter image description here

How to format .eslinterc?

Upvotes: 0

Views: 666

Answers (1)

Quentin
Quentin

Reputation: 944568

Your JavaScript is not valid.

You appear to be starting by having an object:

{
    "parserOptions" : {

etc

But because you have just thrown an object into the file without putting any context (such as a variable assignment first) it is a syntax error.

It looks like you've mixed up the syntax of .eslintrc.js and .eslintrc.json.


Then, you continue with:

module.exports = { "extends": "plugin:prettier/recommended" }; 

… which completely ignores that object.


You need a single object which you can then either export from a JS file or just have in a JSON file.

.eslintrc.json

{
    "extends": "plugin:prettier/recommended",
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "browser": true,
        "node": true,
        "es6": true
    }
}

.eslintrc.js

module.exports = {
    "extends": "plugin:prettier/recommended",
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "browser": true,
        "node": true,
        "es6": true
    }
}

Upvotes: 3

Related Questions