Turbopack: `next build` resolves the path passed to `child_process.fork()` as a module request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/taracutie/nextjs-turbopack-repro
To Reproduce
git clone https://github.com/taracutie/nextjs-turbopack-reprocd nextjs-turbopack-repro && npm cinpm run build
Current vs. Expected behavior
Current
The build step fails resolving a path that is not an import.
▲ Next.js 16.4.0-canary.8 (Turbopack)
> Build error occurred
Error: Turbopack build failed with 1 error:
./lib/spawn-it.ts:6:10
Error: Module not found: Can't resolve '/ROOT/worker.mjs'
4 | export function spawnWorker() {
5 | const script = path.join(process.cwd(), "worker.mjs");
> 6 | return fork(script, []);
| ^^^^^^^^^^^^^^^^
Import trace:
App Route:
./lib/spawn-it.ts
./app/api/x/route.ts
first argument to fork() |
result |
|---|---|
path.join(process.cwd(), "worker.mjs") |
Can't resolve '/ROOT/worker.mjs' |
"/tmp/worker-abs.mjs" (absolute literal, exists) |
Can't resolve '/tmp/worker-abs.mjs' |
process.env.WORKER_PATH ?? "" |
Can't resolve (<dynamic> | '') |
process.env.WORKER_PATH (no constant part) |
builds |
spawn(script, []) and execFile(script, []) with the same exact path build fine.
Expected
The build succeeds.
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026
Available memory (MB): 15614
Available CPU cores: 8
Binaries:
Node: 26.7.0
npm: 11.19.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.4.0-canary.8 // Latest available version is detected (16.4.0-canary.8).
eslint-config-next: N/A
react: 19.2.8
react-dom: 19.2.8
typescript: 5.9.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Turbopack, Module Resolution
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
Fails on 16.0.0-canary.0, 16.0.0, 16.3.3, 16.4.0-canary.7 and 16.4.0-canary.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by cloning the linked reproduction, running npm ci, and then npm run build. Read lib/spawn-it.ts and compare the fork(script, []) case with the reported spawn and execFile cases; done means the reproduction builds successfully when fork receives the path forms shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, node.js
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100