Skip to content

Turbopack: next build resolves the path passed to child_process.fork() as a module request #97952

Description

@taracutie

Link to the code that reproduces this issue

https://github.com/taracutie/nextjs-turbopack-repro

To Reproduce

  1. git clone https://github.com/taracutie/nextjs-turbopack-repro
  2. cd nextjs-turbopack-repro && npm ci
  3. npm 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module ResolutionModule resolution (CJS / ESM, module resolving).TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions