19

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",
[...]
Vítor Norton
  • 408
  • 1
  • 6
  • 12

8 Answers8

11

i actually had this problem the other day ey, 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 git hub for this issue, might not be the same as the one I had, check this link please https://github.com/prettier/prettier-vscode/issues/905

bloo
  • 1,416
  • 2
  • 13
  • 19
8

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

Hope this helps ;)

Claudio Bertozzi
  • 536
  • 4
  • 12
3

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).

2

Open VS Code in the correct directory.

Example, we have:

/dir1/
/dir1/node_modules

In the dir1 directory
. Right click
. Open with Code

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
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

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
1

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

Hope this helps anyone :D

1

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

Max Pekarsky
  • 590
  • 2
  • 6
  • 20
0

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

Fotios Tsakiris
  • 1,310
  • 1
  • 18
  • 24