nextjs - ✅(Solved) Fix [Turbopack Nextjs 16]: Pino - Worker thread cannot find module 'real-require' [2 pull requests, 7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#84766Fetched 2026-04-08 02:18:32
View on GitHub
Comments
7
Participants
4
Timeline
33
Reactions
7
Author
Timeline (top)
subscribed ×9commented ×7referenced ×5cross-referenced ×4

Error Message

Uncaught Exception: Error: Cannot find module 'real-require' Require stack:

  • /var/task/node_modules/.pnpm/[email protected]/node_modules/thread-stream/lib/worker.js at Module._resolveFilename (node:internal/modules/cjs/loader:1365:15) at defaultResolveImpl (node:internal/modules/cjs/loader:1021:19) at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1026:22) at Module._load (node:internal/modules/cjs/loader:1175:37) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:235:24) at Module.require (node:internal/modules/cjs/loader:1445:12) at require (node:internal/modules/helpers:135:16) at Object.<anonymous> (/var/task/node_modules/.pnpm/[email protected]/node_modules/thread-stream/lib/worker.js:3:37) at Module._compile (node:internal/modules/cjs/loader:1688:14)

Fix Action

Fixed

PR fix notes

PR #85734: Turbopack: trace worker_threads worker entry

Description (problem / solution / changelog)

Closes PACK-5688
Closes https://github.com/vercel/next.js/issues/84766

  1. Trace new require("worker_threads").Worker calls
  2. ignore syntax errors in all traced files

This does lead to a build error currently with cargo run --bin turbopack-nft -- --show-issues --graph bench/app-router-server/node_modules/thread-stream/index.js:

error - [analysis] [workspace]/node_modules/.pnpm/[email protected]/node_modules/thread-stream/test/syntax-error.mjs
  [workspace]/node_modules/.pnpm/[email protected]/node_modules/thread-stream/test/syntax-error.mjs:2:6  Parsing ecmascript source code failed
       1 | // this is a syntax error
         +       v
       2 + import
         +       ^
       3 | 
  
  Expected 'from', got '<eof>'

Pulled in by this partly dynamic new Worker() call: https://github.com/pinojs/thread-stream/blob/82e011281b8895bf5e8f70008e0242927fcaf0cb/index.js#L53-L55

(Related to https://github.com/vercel/next.js/pull/84408, where this was previously fixed for extensionless files such as LICENSE)

Changed files

  • turbopack/crates/turbopack-core/src/reference_type.rs (modified, +1/-0)
  • turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs (modified, +21/-8)
  • turbopack/crates/turbopack-ecmascript/src/analyzer/well_known.rs (modified, +38/-8)
  • turbopack/crates/turbopack-ecmascript/src/parse.rs (modified, +3/-9)
  • turbopack/crates/turbopack-ecmascript/src/references/mod.rs (modified, +73/-27)
  • turbopack/crates/turbopack-ecmascript/src/references/node.rs (modified, +97/-2)
  • turbopack/crates/turbopack-ecmascript/src/references/raw.rs (modified, +4/-81)
  • turbopack/crates/turbopack-ecmascript/src/references/util.rs (modified, +87/-2)
  • turbopack/crates/turbopack-ecmascript/src/static_code.rs (modified, +0/-2)
  • turbopack/crates/turbopack-ecmascript/src/utils.rs (modified, +7/-2)
  • turbopack/crates/turbopack-nft/src/nft.rs (modified, +2/-1)
  • turbopack/crates/turbopack-tracing/tests/node-file-trace.rs (modified, +2/-1)
  • turbopack/crates/turbopack-tracing/tests/node-file-trace/integration/pino.js (added, +18/-0)
  • turbopack/crates/turbopack-tracing/tests/node-file-trace/package.json (modified, +2/-0)
  • turbopack/crates/turbopack-tracing/tests/node-file-trace/pnpm-lock.yaml (modified, +146/-0)
  • turbopack/crates/turbopack-tracing/tests/unit.rs (modified, +1/-1)
  • turbopack/crates/turbopack/src/lib.rs (modified, +2/-1)

Code Example

Uncaught Exception: Error: Cannot find module 'real-require'
Require stack:
- /var/task/node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/worker.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1365:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1021:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1026:22)
    at Module._load (node:internal/modules/cjs/loader:1175:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1445:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/var/task/node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/worker.js:3:37)
    at Module._compile (node:internal/modules/cjs/loader:1688:14)

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.1
Relevant Packages:
  next: 16.0.0-beta.0 // Latest available version is detected (16.0.0-beta.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/CHC383/nextjs-turbopack-pino-reproduction

To Reproduce

  1. Deploy the code to Vercel
  2. Visit <url>/api/log
  3. Check the log of the Vercel deployment

Current vs. Expected behavior

Current behavior

With Turbopack in NextJs v16, Pino worker thread throws the following error:

Uncaught Exception: Error: Cannot find module 'real-require'
Require stack:
- /var/task/node_modules/.pnpm/[email protected]/node_modules/thread-stream/lib/worker.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1365:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1021:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1026:22)
    at Module._load (node:internal/modules/cjs/loader:1175:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1445:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/var/task/node_modules/.pnpm/[email protected]/node_modules/thread-stream/lib/worker.js:3:37)
    at Module._compile (node:internal/modules/cjs/loader:1688:14)

Expected behavior

Pino worker thread works without any exception, which is the behavior of using WebPack in NextJs v15.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.1
Relevant Packages:
  next: 16.0.0-beta.0 // Latest available version is detected (16.0.0-beta.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

Turbopack

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

Vercel (Deployed)

Additional context

The transport target pino-pretty in the reproduction repository is just for demo purpose, the same issue happens on any of the targets.

Pino uses thread-stream to send the logs to worker thread when logging asynchronously, which uses real-require to work with webpack import. Looks like Turbopack doesn't bundlereal-require properly.

<sub>PACK-5694</sub>

extent analysis

TL;DR

The issue can be fixed by ensuring real-require is properly bundled with Turbopack in Next.js v16.

Guidance

  • Investigate Turbopack configuration to ensure real-require is included in the bundle.
  • Check if there are any known issues or fixes in Turbopack or Next.js v16 related to bundling real-require.
  • Consider using a different logging library that doesn't rely on real-require or thread-stream.
  • Verify if the issue persists with the latest version of thread-stream and real-require.

Example

No code snippet is provided as the issue seems to be related to the bundling process rather than a specific code error.

Notes

The issue might be specific to the combination of Turbopack, Next.js v16, and the thread-stream library. Further investigation into the bundling process and potential workarounds is needed.

Recommendation

Apply a workaround by exploring alternative logging libraries or configurations that don't rely on real-require until a proper fix is available for Turbopack and Next.js v16.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING