8

I have Eslint and JSCS setup to reformat some code base with airbnb js style guide in WebStorm. I have been using this setup effectively for the past 2 days, but all of a sudden, WebStorm started throwing this error...

Problem with ESLint reformatting:index.js: Initialization error (ESLint). Unexpected identifier

enter image description here

I thought maybe I had some error in my .eslintrc but then I had used the same config to successfully refactor about 150 files before this sudden error. Prior to this, the JSCS compiler was occasionally throwing "less than a minute timeout" exceptions, but then I would fix this with closing and reopening the file. The eslint though seems not to be falling for this trick.

This is my .eslintrc config

{
  "extends": "airbnb",
  "env": {
    "browser": true,
    "node": true
  },
  "globals": {
    "document": false
  },
  "rules": {
    "validateIndentation": 4,
    "func-names": [
      "error",
      "never"
    ],
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "jsx-a11y/label-has-for": [
      2,
      {
        "components": [
          "Label"
        ],
        "required": {
          "some": [
            "nesting",
            "id"
          ]
        },
        "allowChildren": false
      }
    ],
    "jsx-a11y/anchor-is-valid": [
      "error",
      {
        "components": [
          "Link"
        ],
        "specialLink": [
          "to",
          "hrefLeft",
          "hrefRight"
        ],
        "aspects": [
          "noHref",
          "invalidHref",
          "preferButton"
        ]
      }
    ]
  }
}

Some part of package.json

{
    "eslint": "^4.14.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-flowtype": "^2.40.1",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.5.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dev-utils": "^4.2.1",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-router-dom": "^4.2.2",
  },
  "babel": {
    "presets": [
      "react-app",
      "flow"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  }
}

Can some one throw me some pointers on how I can go about fixing this. I suspect it might be more of a WebStorm error than Eslint.

PS: Forgive me if this question might be better suited at superuser. I just thought it's most likely someone here might have faced the same issue.

6
  • @lena, Problem with ESLint reformatting:index.js: Initialization error (ESLint). Unexpected identifier is the same message that appears on clicking show ballon link. It just re formats the same message in a better looking ballon tooltip box. Jan 9, 2018 at 16:42
  • no idea:( please share a sample project that can be used to recreate the issue, plus your idea.log (intellij-support.jetbrains.com/hc/en-us/articles/…)
    – lena
    Jan 9, 2018 at 17:31
  • 1
    @lena, was not able to recreate the issue with a fresh project the were passing the linting with the same setup. However testing the eslint on non js files produced a much more detailed error pointing to eslinting in lodash. yarn upgrade helped Jan 10, 2018 at 13:27
  • 1
    I had a simular problem, but mine got solved by updating node from version 8 to 14. Simplest way was just to download a new version of node from nodejs.org and run the installer.
    – Rikard
    Feb 5, 2021 at 6:17
  • 4
    @Rikard's fix works. If you need to do this inside WebStorm, open Preferences, go to Language and Frameworks->Node.js and NPM->Node interpreter. Mine defaulted to the first version of Node I'd installed, but I also use nvm. I fixed my issue by pointing to a newer version of Node from within nvm.
    – corinna000
    Mar 14, 2021 at 17:54

2 Answers 2

19

i use this pattern for my eslint configuraion in phpstorm and error has gone now,

{**/*,*}.{js,ts,jsx,tsx,html,vue},{!node_modules/*}
2
3

Solved by a yarn upgrade


My attempts at recreating the issue with a fresh project failed, with the same configs, both eslint and jscs were running successfully.

However on using the WebStorm context menu command Apply ESlint Code Style Rules on non js files(tested on .eslintrc itself), i got a much more detailed error.

Error on attempt to find parent and base ESLint configuration files of '.eslintrc': [projectpath]\node_modules\lodash\lodash.js:386 '\u0149': ''n', '\u017f': 's',

I double checked lodash package node_modules and package.json, tripple checked the settings configs(Eslint & JSCS) and was sure I had identical setup to the test projects that were linting without errors.

Running yarn upgrade lodash saved my hair. Since I was already running the latest lodash, I think yarn's Resolving and Rebuilding the packages did the trick.

Hope someone might find this helpful somewhere along the line.

2
  • 1
    npm upgrade saved me
    – Vladimir
    Apr 8, 2021 at 19:36
  • 1
    I get the same error after adding a newer package. yarn upgrade eslint fixed my PyCharm issue.
    – kujiy
    Dec 19, 2022 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.