vscode-eslint: pnpm, eslint & typescript - Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js

In my project, using pnpm, Node v14.6.0, Eslint 7.23.0 and the plugin’s latest version, I get this error: Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js

Unfortunately, I cannot share the project itself to allow for easy reproduction. I went through all the relevant issues and tried the suggestions without any luck.

In the dir in which I open code, I successfully run which pnpm (I saw this was referenced in another issue), and also running from the terminal pnpm run eslint is successful. I set my Workspace Settings for the plugin to use pnpm as the package manager.

Any advice on how I can debug this further?

It might be worth noting that the .eslintrc.js in question is not the one in my project, but rather one referenced from one of my dependencies, which my .eslintrc.js extends.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 16 (6 by maintainers)

Most upvoted comments

came across this while migrating a repo I work on to pnpm. I had to one by one hoist as described here. happy to repro if we want to dive back in.

I have: pnpm 7.1.5 a mono repo: app1

  • .eslintrc.js extends shared-eslint-config, and installs it as a workpsace dependency in pnpm

app2

  • .eslintrc.js extends shared-eslint-config, and installs it as a workpsace dependency in pnpm

shared-eslint-config

and from terminal eslint works fine without hoisting, but I added this:

public-hoist-pattern[]=*eslint-plugin-*

in my .npmrc file.

and that cleared it up for me.

I tried various settings as well from other similarly reported issues:

settings.json:

  "eslint.nodePath": "/Users/username/admin-pnpm/node_modules/.pnpm/node_modules",
  "eslint.runtime": "/Users/username/Library/Caches/fnm_multishells/9686_1653421493848/bin/node",
  "eslint.workingDirectories": [ "./app1", "./app2" ],
  "eslint.packageManager": "pnpm",
  "npm.packageManager": "pnpm",

without hoisting I get this:

Uncaught exception received.
Error: Failed to load plugin 'jsx-a11y' declared in '.eslintrc.js » shared-eslint-config': Cannot find module 'eslint-plugin-jsx-a11y'
Require stack:
- /Users/username/admim-pnpm/app1/__placeholder__.js
Referenced from: /Users/username/admim-pnpm/shared-eslint-config/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at Object.resolve (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js:28:50)
    at ConfigArrayFactory._loadPlugin (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/config-array-factory.js:1017:39)
    at ConfigArrayFactory._loadExtendedPluginConfig (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/config-array-factory.js:837:29)
    at ConfigArrayFactory._loadExtends (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/config-array-factory.js:779:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/config-array-factory.js:720:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (/Users/username/admin-pnpm/node_modules/.pnpm/@eslint+eslintrc@0.4.3/node_modules/@eslint/eslintrc/lib/config-array-factory.js:665:20)
    at _normalizeObjectConfigData.next (<anonymous>)

still not solved for me. i’m using eslint-config-airbnb-typescript which uses @typescript-eslint/eslint-plugin as peers, I set auto-install-peers=true in .npmrc. But @typescript-eslint/eslint-plugin not added to node_modules, even though it’s listed in pnpm-lock.yaml

I found that the issue has to do with public-hoist-pattern[] I have defined in my .npmrc. Does this give any relevant clues that could help? My issue with creating a reproducible repo is that most of the packages used by the project are private. The reason for the public-hoist-pattern is that this is how the project runs in my CI environment which I don’t have control over, and I want to run my local project in an environment as close as possible to CI.

I will give another try to creating a reproducible repo over the weekend but really hoping that this will give some clues. Thanks a lot for your help.