Turbopack never passes comments to SWC wasm plugins unless a file has both leading AND trailing comments
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/instagibb/turbopack-comments-repro
To Reproduce
With Turbopack (NextJS default)
- Run
npm run dev - Browse to http://localhost:3000/
- The page reads istanbul's
__coverage__global store and renders the result (see DevTools console if preferred). The istanbul ignore hint comment inleading-only.tshas not been processed and the function was instrumented whilewith-trailing.tswhich is identical except for one trailing comment has the hint honoured and there is no instrumenting
For comparison with Webpack
- Run
npm run dev:webpack - Browse to http://localhost:3000/
- The output shows that the istanbul ignore hint comment has been honoured in both instances
Or for a fully automatic test
- Run
npm run checkto build with both Turbopack and Webpack and print the comparison
Current vs. Expected behavior
Current behaviour: Turbopack only passes the comments to SWC plugins when a file contains both leading AND trailing comments. Otherwise the plugin receives an empty comment store, so any comment-driven behaviour silently does nothing (no error)
See: swc_ecma_transform_plugins.rs lines 136–141 on canary
let should_enable_comments_proxy =
!ctx.comments.leading.is_empty() && !ctx.comments.trailing.is_empty();
//[TODO]: as same as swc/core does, we should set should_enable_comments_proxy
// depends on the src's comments availability. For now, check naively if leading
// / trailing comments are empty.
Expected behaviour: Turbopack should pass comments to SWC plugins when a file contains any comments (leading OR trailing)
let should_enable_comments_proxy =
!ctx.comments.leading.is_empty() || !ctx.comments.trailing.is_empty();
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.5.0: Tue Jun 9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041
Available memory (MB): 49152
Available CPU cores: 12
Binaries:
Node: 24.14.1
npm: 11.11.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.4.0-canary.6 // Latest available version is detected (16.4.0-canary.6).
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, SWC
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (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 in turbopack/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs around lines 136–141 and inspect how comment availability enables the SWC plugin proxy. Run the linked reproduction with npm run check, then verify that files with only leading or only trailing comments receive comments and match the Webpack comparison.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, rust, typescript
- Domain
- build-system, compilers, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100