Skip to content

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

Open
@eddienubes

Description

@eddienubes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OutputRelated to the the output configuration option.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions