Reproduction link or steps
elecmonkey/rolldown-banner-shebang-reproduction
What is expected?
Rolldown may should just throw an error, or preserve the full bundle body and produce invalid output, similar to postBanner. When using postBanner, the output becomes:
#!/usr/bin/env node
#!/usr/bin/env node
//#region cli.js
console.log("hello from cli");
//#endregion
The second line is invalid syntax, and the CLI emits a warning: [DUPLICATE_SHEBANG] Warning: Both the code and postBanner contain shebang in "with-banner.js". This will cause a syntax error.
Rolldown could emit a warning for the duplicate shebang situation, but I think it should not generate an empty bundle containing only a shebang line.
What is actually happening?
Rolldown first generates output containing two shebang lines, then during a later processing step the bundle body is lost. The final emitted file collapses to only:
with the rest of the generated bundle missing.
Based on instrumenting the current rolldown codebase, the generated chunk is still intact immediately after render, but it already contains two shebang lines. The bundle body disappears later during minify_chunks, which calls EcmaCompiler::dce_or_minify. That path reparses the already-generated chunk using Parser::new(...).parse().program without checking parse errors first. Because duplicate shebangs produce invalid JavaScript, the reparsing step appears to recover into a broken AST, and the subsequent codegen emits only the first shebang line. So the problem seems to be a combination of two issues:
output.banner can introduce a duplicate shebang when the source already has one.
- The later minify/DCE path reparses that invalid output without handling parse errors safely.
System Info
System:
OS: macOS 15.7.3
CPU: (8) arm64 Apple M2
Memory: 153.69 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.4.1 - /Users/elecmonkey/.vite-plus/bin/node
Yarn: 1.22.22 - /Users/elecmonkey/.nvm/versions/node/v24.4.1/bin/yarn
npm: 11.4.2 - /Users/elecmonkey/.vite-plus/bin/npm
pnpm: 10.33.0 - /Users/elecmonkey/.nvm/versions/node/v24.4.1/bin/pnpm
bun: 1.3.3 - /Users/elecmonkey/.bun/bin/bun
Deno: 2.6.5 - /opt/homebrew/bin/deno
Browsers:
Chrome: 146.0.7680.178
Edge: 146.0.3856.97
Firefox: 136.0.4
Safari: 26.2
npmPackages:
rolldown: 1.0.0-rc.13 => 1.0.0-rc.13
Any additional comments?
No response
Reproduction link or steps
elecmonkey/rolldown-banner-shebang-reproduction
What is expected?
Rolldown may should just throw an error, or preserve the full bundle body and produce invalid output, similar to
postBanner. When usingpostBanner, the output becomes:The second line is invalid syntax, and the CLI emits a warning: [DUPLICATE_SHEBANG] Warning: Both the code and postBanner contain shebang in "with-banner.js". This will cause a syntax error.
Rolldown could emit a warning for the duplicate shebang situation, but I think it should not generate an empty bundle containing only a shebang line.
What is actually happening?
Rolldown first generates output containing two shebang lines, then during a later processing step the bundle body is lost. The final emitted file collapses to only:
#!/usr/bin/env nodewith the rest of the generated bundle missing.
Based on instrumenting the current rolldown codebase, the generated chunk is still intact immediately after render, but it already contains two shebang lines. The bundle body disappears later during
minify_chunks, which callsEcmaCompiler::dce_or_minify. That path reparses the already-generated chunk usingParser::new(...).parse().programwithout checking parse errors first. Because duplicate shebangs produce invalid JavaScript, the reparsing step appears to recover into a broken AST, and the subsequent codegen emits only the first shebang line. So the problem seems to be a combination of two issues:output.bannercan introduce a duplicate shebang when the source already has one.System Info
System: OS: macOS 15.7.3 CPU: (8) arm64 Apple M2 Memory: 153.69 MB / 24.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.4.1 - /Users/elecmonkey/.vite-plus/bin/node Yarn: 1.22.22 - /Users/elecmonkey/.nvm/versions/node/v24.4.1/bin/yarn npm: 11.4.2 - /Users/elecmonkey/.vite-plus/bin/npm pnpm: 10.33.0 - /Users/elecmonkey/.nvm/versions/node/v24.4.1/bin/pnpm bun: 1.3.3 - /Users/elecmonkey/.bun/bin/bun Deno: 2.6.5 - /opt/homebrew/bin/deno Browsers: Chrome: 146.0.7680.178 Edge: 146.0.3856.97 Firefox: 136.0.4 Safari: 26.2 npmPackages: rolldown: 1.0.0-rc.13 => 1.0.0-rc.13Any additional comments?
No response