Skip to content
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

PNPM Workspaces + Standalone cannot find module get-network-host upon launch #77472

Open
eddienubes opened this issue Mar 24, 2025 · 2 comments
Labels
Output Related to the the output configuration option.

Comments

@eddienubes
Copy link

Link to the code that reproduces this issue

https://github.com/eddienubes/next-pnpm-standalone-bug-repro/tree/main

To Reproduce

Preliminary actions

Standard monorepo setup, where one of the projects is next.js.

nvm use # (optionally install)
pnpm install
cd projects/ui
pnpm build
node .next/standalone/server.js # launch fails

Error:

Error: Cannot find module '../../lib/get-network-host'

Current vs. Expected behavior

ER:
Standalone server successfully launches
AR:
Server.js inside standalone folder fails to locate a module ../../lib/get-network-host
with error:

Error: Cannot find module '../../lib/get-network-host'
Require stack:
- /Users/admin/Code/next-bug/projects/ui/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js
- /Users/admin/Code/next-bug/projects/ui/.next/standalone/server.js

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 12
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.6.1
Relevant Packages:
  next: 15.2.3 // Latest available version is detected (15.2.3).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: standalone

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

Output

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

next build (local)

Additional context

Upon further inspection I noticed that after pnpm install and before pnpm build (next build), the projects/ui/node_modules doesn't have .pnpm folder. The projects/ui/node_modules as expected contains symlinks to the root node_modules/.pnpm with next, react and react-dom packages.

However, after I run next build the contents of projects/ui/node_modules is modified and the .pnpm folder appears with:

node_modules/.pnpm
├── [email protected][email protected][email protected][email protected][email protected]
│   └── node_modules
│       └── next
│           └── dist
│               ├── compiled
│               │   └── jest-worker
│               │       ├── processChild.js
│               │       └── threadChild.js
│               ├── pages
│               │   ├── _app.js
│               │   └── _document.js
│               └── server
│                   ├── lib
│                   │   └── start-server.js
│                   ├── next-server.js
│                   ├── next.js
│                   ├── require-hook.js
│                   └── route-modules
│                       ├── app-page
...
│                       └── pages
...
└── [email protected][email protected]
    └── node_modules
        └── styled-jsx
            ├── index.js
            └── style.js

Almost the same contents appear in the standalone bundle itself:

.next/standalone/node_modules
├── next -> ../../../node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next
└── react -> ../../../node_modules/.pnpm/[email protected]/node_modules/react

So, there's clearly nothing that can resolve to ../../lib/get-network-host.
For some reason the bundle next dist directory is truncated.

@github-actions github-actions bot added the Output Related to the the output configuration option. label Mar 24, 2025
@HenriqueSenaDev
Copy link

Hello! This seems to be a #48017 replica.
In a nutshel, pnpm centralized storage with synlinks does not woks really well with Next standalone applications.
A workaround is configuring your .npmrc to force the traditional approach (used by npm and yarn) when installing dependencies.
node-linker=hoisted

@eddienubes
Copy link
Author

eddienubes commented Mar 25, 2025

@HenriqueSenaDev
I've seen that issue, however the node-linker=hoisted doesn't seem to have an effect on next build

Indeed, the node_modules directory becomes yarn-like flat and pnpm doesn't even create projects/ui/node_modules, but next build still creates a projects/ui/node_modules by itself with truncated next and styled-jsx packages.

This leads to Error: Cannot find module '../../lib/get-network-host' nevertheless (just tried it again with my repro)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output Related to the the output configuration option.
Projects
None yet
Development

No branches or pull requests

2 participants