vs-code-prettier-eslint: Error: Cannot find module '@typescript-eslint/parser'

Describe the bug I have a v4.0.0-beta version of extension, and on formatting action it shows me the error:

Error: Cannot find module '@typescript-eslint/parser'
Require stack:
- /home/user/.vscode-server/extensions/rvest.vs-code-prettier-eslint-4.0.0-beta/dist/extension.js
- /home/user/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/out/vs/loader.js
- /home/user/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/out/bootstrap-amd.js
- /home/user/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/out/bootstrap-fork.js 

But the ‘@typescript-eslint/parser’ package is installed locally:

$ yarn list --pattern  '@typescript-eslint/parser'
yarn list v1.22.5
├─ @typescript-eslint/parser@5.8.1
└─ prettier-eslint@10.1.1
   └─ @typescript-eslint/parser@3.10.1

To Reproduce Steps to reproduce the behavior:

  1. Install the v4.0.0-beta version of the extension.
  2. Install ‘@typescript-eslint/parser’ via yarn add @typescript-eslint/parser@^5.0.1
  3. Select “Format Document With » Prettier ESLint”.
  4. See the error

Versions (please complete the following information):

  • Visual Studio Code: Version: 1.63.2 Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3 Date: 2021-12-15T09:39:46.686Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.13.0-22-generic

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@MurzNN Rename your .eslintrc to .eslintrc.js to make it a JavaScript file. Then add

tsconfigRootDir: __dirname

under

"project": "./tsconfig.json"

You are getting an error because the ESLint TS parser cannot find your tsconfig.json

thank you this fixed it for me. for anyone else making that change just remember a .js uses module.exports which you add before the { of the json content

  1. change to .js
  2. add the exports
module.exports = { ... }

@MurzNN Rename your .eslintrc to .eslintrc.js to make it a JavaScript file. Then add

tsconfigRootDir: __dirname

under

"project": "./tsconfig.json"

You are getting an error because the ESLint TS parser cannot find your tsconfig.json

I tried to see where require.resolve is looking for and I got:

  • /Users/[user]/.vscode/extensions/rvest.vs-code-prettier-eslint-3.0.4/dist/node_modules
  • /Users/[user]/.vscode/extensions/rvest.vs-code-prettier-eslint-3.0.4/node_modules
  • /Users/[user]/.vscode/extensions/node_modules
  • /Users/[user]/.vscode/node_modules
  • /Users/[user]/node_modules
  • /Users/node_modules
  • /node_modules

…which is the expected behavior from Node AFAIK. But no, there’s no such package in there :p

Should this extension add @typescript-eslint/parser as a dependency? Otherwise, how can we use the locally installed package (from the current project) or the one that has been globally installed?

Edit: I suspect that we might have the same issue with vue-eslint-parser.

See https://github.com/prettier/prettier-eslint/blob/master/src/index.js#L126

@idahogurl Succeed, Very Nice. (^o^)/~

🚀 UPDATE: Fixed it! 🥳

I just removed the unused jsx-a11y plugin from my ESLint config.

I wasn’t using JSX in my project but it had the following ESLint config:

  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'plugin:jsx-a11y/recommended',
    'airbnb-base/legacy',
    'prettier',
  ],
  plugins: ['@typescript-eslint', 'prettier', 'jsx-a11y', 'import'],

Because I had copied the .eslintrc.js file from another project.

Also I didn’t have the eslint-plugin-jsx-a11y package installed, installing it also fixes the issue.


Original comment:

Getting this error with the latest pre-release version (v5.0.1):

Error: Cannot find module '@typescript-eslint/parser'
Require stack:
- c:\Users\win10user\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.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 
Error: Cannot find module '@typescript-eslint/parser'
Require stack:
- c:\Users\win10user\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.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
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
    at Function.h.resolve (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:761)
    at Lge (c:\Users\win10user\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.1\dist\extension.js:180:1235)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The following didn’t work:

@MurzNN Rename your .eslintrc to .eslintrc.js to make it a JavaScript file. Then add

tsconfigRootDir: __dirname

under

"project": "./tsconfig.json"

You are getting an error because the ESLint TS parser cannot find your tsconfig.json

@the-vampiire That code is from ‘prettier-eslint’. It gets bundled during the build. I’ll take a look later today hopefully.