next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Standalone can't be builded if pnpm-virtual-store outside of node_modules

Open baymer opened this issue 4 months ago • 2 comments

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/relaxed-cohen-7cps4h

To Reproduce

pnpm i --virtual-store-dir ~/.cache/vstore/app/
next build --webpack

Current vs. Expected behavior

current behavior

in the .next/standalone/node_modules will be incorrect dependencies with broken symlinks

expected behavior

in the .next/standalone/node_modules correct dependencies

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.6.0-canary.34 // Latest available version is detected (15.6.0-canary.34).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: N/A
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

  • our pnpm-virtual-store outside of node_modules is a performance optimisation

  • pnpm experiments with global virtual store https://pnpm.io/settings#enableglobalvirtualstore

baymer avatar Sep 29 '25 14:09 baymer

This is because the packages are "outside" the project root. e.g. in /Users/robbie/Library/pnpm/store/v10

You can work around this by setting the root to a shared ancestor:

  turbopack: {
    // turbopack must be able to resolve packages from the global store
    root: "/",
  },

I can't imagine this is very good practice. Ideally next would include global package stores by default so that the root wouldn't need to change.

RJWadley avatar Dec 11 '25 22:12 RJWadley

I can't imagine this is very good practice. Ideally next would include global package stores by default so that the root wouldn't need to change.

Or maybe allow multiple roots

r34son avatar Dec 11 '25 22:12 r34son