How do I fix this error message "Initialization error (Eslint). Unexpected Identifier"?
Asked Answered
D

2

9

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.

Dugaid answered 9/1, 2018 at 11:57 Comment(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.Dugaid
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/…)Untouchable
@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 helpedDugaid
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.Longfaced
@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.Clansman
As corinna000 already hinted, this also applies to other JetBrains products such as RubyMine. (Tested on 2022.3)Mcclintock
D
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.

Dugaid answered 10/1, 2018 at 13:19 Comment(2)
npm upgrade saved meCoreen
I get the same error after adding a newer package. yarn upgrade eslint fixed my PyCharm issue.Karmen
U
21

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

{**/*,*}.{js,ts,jsx,tsx,html,vue},{!node_modules/*}
Unspeakable answered 1/8, 2021 at 7:48 Comment(2)
Good point using ,{!node_modules/*}, It solved the error for meHine
I agree with A-Palgy. You set this pattern in the ESLint settings at "Run for files". It fixed ESLint: Inizielization error (ESLint). Unexpected token ... for me. These settings are directly linked at the end of this error message line.Mcclintock
D
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.

Dugaid answered 10/1, 2018 at 13:19 Comment(2)
npm upgrade saved meCoreen
I get the same error after adding a newer package. yarn upgrade eslint fixed my PyCharm issue.Karmen

© 2022 - 2024 — McMap. All rights reserved.