27

I'm getting the following error from Prettier Eslint Output on VSCode when saving the file.

Error: Cannot find module '@typescript-eslint/parser'
Require stack:
- c:\Users\vtnor\.vscode\extensions\rvest.vs-code-prettier-eslint-0.4.1\dist\extension.js
- c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-fork.js

My package json is:

[...]
"typescript": "^4.2.2",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"prettier": "^2.2.1",
"prettier-eslint": "^12.0.0",
[...]

9 Answers 9

17

I actually had this problem the other day; you need to go to your .eslintrc and make sure that the module is there under the parser property of the config. Should look something like this in the end:

{
  //...

  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],

  //...
}

This should cover the essentials regarding dependencies in your linter. Hope it helps.

Edit

I checked GitHub for this issue, might not be the same as the one I had, check this link please.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried to add and remove this parser line. Currently I do have this line and I moved it - just in case - to be after extends. Still got the same error.
This isn't the same error, but I did try to restart my PC. Didn't work.
not working please let me know if you find any solution @VítorNorton
Thank you, it worked for me. Make sure that you also restart vscode to see the warning disappear.
13

Had this problem also, I resolved disabling, then reloading and re-enabling ESLint extension of VSCode.

Hope this helps ;)

Comments

6

I discovered that the cause of the error in my case was ESLint itself was throwing an error. I discovered this by looking at the ESLint output in VSCode. The fix was to update one of my other dependencies (eslint-plugin-import).

1 Comment

this should be the best answer! I found out that one of the plugins was not loading since it shouldn't be there and the parser was throwing in the Prettier Eslint output but the real issue was found in the Eslint Output
3

Installing @typescript-eslint/eslint-plugin and then reloading VSCode solved the issue for me.

Hope this helps anyone :D

Comments

2

Open VS Code in the correct directory.

Example, we have:

/dir1/
/dir1/node_modules

In the dir1 directory
. Right click
. Open with Code

Comments

1

The problem probably that .eslintrc is not finding necessary modules because that are in a wrong location. .eslintrc needs to have folder node_modules right next to it. This can easily be achieved by putting .eslintrc into the project folder and creating package.json right next to it. Then node_modules will also be created in the project folder and the necessary (and installed) modules will be found.

Your project folder should look similar to:

content of project folder

Comments

1

Fixed this with npm remove @typescript-eslint/parser && npm install @typescript-eslint/parser

Comments

1

In my case, I was already using eslint-plugin-import and eslint-import-resolver-typescript, but @typescript-eslint/parser was a transitive dependency of typescript-eslint. Therefore, installing @typescript-eslint/parser explicitly, fixed the issue for me.

Comments

0

I just added the metro.config.js (like I did for an other fix for babel.config.js) to .eslintignore.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.