Turbopack `require.context` ESM interop is different compared to Webpack
Nobody has claimed this yet.
- 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
To Reproduce
- Run
npm run dev - Visit
http://localhost:3000/ - Observe the console (not the browser console), see
"File contents\n"in the logs. - Terminate the process, then run
npm run dev-turbo - 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
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 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