vercel / vercel/next.js

Turbopack `require.context` ESM interop is different compared to Webpack

Open
#78,406 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

linear: turbopack Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Originally reported by @Vinnl in https://github.com/vercel/next.js/pull/78148#issuecomment-2821067072

Link to the code that reproduces this issue

https://github.com/Vinnl/tmp-repro-next-turbopack-require-context/commit/0878b97d96e1fdb8c7478531787073fb57e6f0b1

To Reproduce
  1. Run npm run dev
  2. Visit http://localhost:3000/
  3. Observe the console (not the browser console), see "File contents\n" in the logs.
  4. Terminate the process, then run npm run dev-turbo
  5. Visit http://localhost:3000/
Current vs. Expected behavior

What happened:

I saw {"default":"File contents\n"} in the logs.

What I expected:

See "File contents\n" in the logs, just like with the Webpack build.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Apr 10 21:50:55 UTC 2025
  Available memory (MB): 15691
  Available CPU cores: 8
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 9.4.0
Relevant Packages:
  next: 15.4.0-canary.2 // Latest available version is detected (15.4.0-canary.2).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.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)

next dev (local)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction commit and run its npm run dev and npm run dev-turbo commands, comparing the server console output for require.context. Trace the Turbopack path involved in ESM interop and compare it with the Webpack behavior. Done means both commands log "File contents\n" rather than the default-object form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.