Skip to content

Failed to resolve plugin when using pnpm custom virtual-store-dir #61584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
r34son opened this issue Apr 16, 2025 · 6 comments
Open

Failed to resolve plugin when using pnpm custom virtual-store-dir #61584

r34son opened this issue Apr 16, 2025 · 6 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@r34son
Copy link

r34son commented Apr 16, 2025

🔎 Search Terms

pnpm virtual-store-dir plugin resolve

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

https://codesandbox.io/p/devbox/5t3rgv

🙁 Actual behavior

see .vscode/settings.json:

{
    "typescript.tsdk": "node_modules/typescript/lib",
    "typescript.tsserver.log": "terse"
}

and .npmrc:

virtual-store-dir=${HOME}/.cache/pnpm-virtual-store

and tsconfig.json:

...
"plugins": [
  {
    "name": "next"
  }
],

Using workspace version of typescript with custom pnpm virtual-store-dir fails to load plugins

  1. Install dependencies
  2. Open ts file
  3. Press cmd+shift+p
  4. type open tsserver log and select command
  5. You will find this logs:
Info 13   [07:41:44.241] Enabling plugin next from candidate paths: /root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js/../../..
Info 14   [07:41:44.241] Loading next from /root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js/../../.. (resolved to /root/.cache/pnpm-virtual-store/[email protected]/node_modules/node_modules)
Info 15   [07:41:44.256] Failed to load module 'next' from /root/.cache/pnpm-virtual-store/[email protected]/node_modules/node_modules: Error: Could not resolve JS module 'next' starting at '/root/.cache/pnpm-virtual-store/[email protected]/node_modules/node_modules'. Looked in: /root/.cache/pnpm-virtual-store/[email protected]/node_modules/next/package.json, /root/.cache/pnpm-virtual-store/[email protected]/node_modules/next.js, /root/.cache/pnpm-virtual-store/[email protected]/node_modules/next.jsx, /root/.cache/pnpm-virtual-store/[email protected]/node_modules/next/index.js, /root/.cache/pnpm-virtual-store/[email protected]/node_modules/next/index.jsx, /root/.cache/pnpm-virtual-store/node_modules/next/package.json, /root/.cache/pnpm-virtual-store/node_modules/next.js, /root/.cache/pnpm-virtual-store/node_modules/next.jsx, /root/.cache/pnpm-virtual-store/node_modules/next/index.js, /root/.cache/pnpm-virtual-store/node_modules/next/index.jsx, /root/.cache/node_modules/next/package.json, /root/.cache/node_modules/next.js, /root/.cache/node_modules/next.jsx, /root/.cache/node_modules/next/index.js, /root/.cache/node_modules/next/index.jsx, /root/node_modules/next/package.json, /root/node_modules/next.js, /root/node_modules/next.jsx, /root/node_modules/next/index.js, /root/node_modules/next/index.jsx, /node_modules/next/package.json, /node_modules/next.js, /node_modules/next.jsx, /node_modules/next/index.js, /node_modules/next/index.jsx
    at resolveJSModule (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:44657:11)
    at Object.require (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:8385:30)
    at Function.importServicePluginSync (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:185646:27)
    at _ProjectService.requestEnablePlugin (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:191532:16)
    at ConfiguredProject2.enablePlugin (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:186944:25)
    at ConfiguredProject2.enablePluginsWithOptions (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:187700:14)
    at _ProjectService.loadConfiguredProject (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:189606:13)
    at _ProjectService.reloadConfiguredProject (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:189880:10)
    at ConfiguredProject2.updateGraph (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:187629:29)
    at updateWithTriggerFile (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:188177:11)
    at updateConfiguredProject (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:188185:9)
    at updateProjectFoundUsingFind (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:188120:28)
    at _ProjectService.findCreateOrReloadConfiguredProject (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:190771:62)
    at _ProjectService.tryFindDefaultConfiguredProjectForOpenScriptInfo (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:190806:25)
    at _ProjectService.tryFindDefaultConfiguredProjectAndLoadAncestorsForOpenScriptInfo (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:190964:25)
    at _ProjectService.assignProjectToOpenedScriptInfo (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:190717:27)
    at /root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:191270:27
    at Array.forEach (<anonymous>)
    at _ProjectService.applyChangesInOpenFiles (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:191267:56)
    at updateOpen (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:192499:29)
    at /root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:195218:15
    at IpcIOSession.executeWithRequestId (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:195207:14)
    at IpcIOSession.executeCommand (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:195216:29)
    at IpcIOSession.onMessage (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js:195264:68)
    at process.<anonymous> (/root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/_tsserver.js:525:14)
    at process.emit (node:events:513:28)
    at emit (node:internal/child_process:946:14)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
Info 16   [07:41:44.256] Couldn't find next

The problem is that path to tsserver is resolved to the custom pnpm virtual-store-dir and it is impossible to resolve path to plugin from it.

The path comes from here https://github.com/microsoft/TypeScript/blob/main/src/server/project.ts#L2109
Why it does not return node_modules/typescript/lib and instead return /root/.cache/pnpm-virtual-store/[email protected]/node_modules/typescript/lib/typescript.js/../../..?

🙂 Expected behavior

Plugin starts correctly using pnpm custom virtual-store-dir

Additional information about the issue

No response

@RyanCavanaugh
Copy link
Member

We don't have support for pnpm's virtual-store-dir concept. Since tsserver has no idea which package manager you're using, it doesn't have any way to even know which custom package manager semantics to look for or respect/ignore. Plugins need to be resolvable through node_modules.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Apr 17, 2025
@r34son
Copy link
Author

r34son commented Apr 18, 2025

@RyanCavanaugh Any workarounds to suggest?

@RyanCavanaugh
Copy link
Member

IIRC a plugin path can be a relative filename, so you could specify it that way (e.g. ./whatever_path/plugin_name/subdir/index.js). You can also add plugin probe path locations via editor configuration, see microsoft/vscode#45856 for context on that.

@r34son
Copy link
Author

r34son commented Apr 18, 2025

IIRC a plugin path can be a relative filename, so you could specify it that way (e.g. ./whatever_path/plugin_name/subdir/index.js). You can also add plugin probe path locations via editor configuration, see microsoft/vscode#45856 for context on that.

Tried it, but it seems not the right solution

Image

@r34son
Copy link
Author

r34son commented Apr 18, 2025

IIRC a plugin path can be a relative filename, so you could specify it that way (e.g. ./whatever_path/plugin_name/subdir/index.js).

Nope, see

if (
!pluginConfigEntry.name ||
isExternalModuleNameRelative(pluginConfigEntry.name) ||
/[\\/]\.\.?(?:$|[\\/])/.test(pluginConfigEntry.name)
) {
this.logger.info(`Skipped loading plugin ${pluginConfigEntry.name || JSON.stringify(pluginConfigEntry)} because only package name is allowed plugin name`);
return;
}

@RyanCavanaugh
Copy link
Member

pluginPaths should still work, it just needs to be in the correct config.

To advise further I'd probably need to know why you're using a custom module location in the first place; this isn't a very common scenario so there might be other constraints at play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants