You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Building with --format cjs and --no-bundle ignores cjs format #29187
Create a TypeScript file with some simple imports and exports and build it with a specific build command: bun build ./index.ts --outfile ./index.js --target node --format cjs --no-bundle
What is the expected behavior?
I'm looking to be able to output a file that is still readable and uses external imports, meanwhile being compatible with CommonJS.
Thanks for testing! The previous commits handled every export form but I'd missed the s_import handler entirely — it was still emitting raw import statements regardless of format. Fixed in b7924a1: the --no-bundle --format cjs path now rewrites import to require too (simple destructuring, no runtime helpers). Could you rebuild and retest? The new output for your example should be:
Nice job! Can confirm that it's working perfectly now!
Not sure why you commented here when I replied in the pull request though. Regardless it looks good.
Thanks — that's exactly it. printCommonJS was using a NoOpRenamer unconditionally because historically it was only called from the bundler path (after the linker had already run). On the new no-bundle path the parser runs with minify_identifiers on but never gets a renamer. Fixed in 451c9ba: mirrored printAst"'s MinifyRenamer" setup in printCommonJS", and updated printBundledExportsForBinding" to read symbol.original_name" for the Object.defineProperty" key (external contract) and `renamer.nameForSymbol(ref)" for the getter target (local), so only the local binding shrinks under minify.
Thanks for digging through the log! Yeah that confirms what I suspected — env: bun: No such file or directory / ci-remap server did not start: code 127 is CI agent setup failing to find bun in `PATH" on the darwin-aarch64 runner. Nothing to do with this PR's code: the same pair of darwin-aarch64 lanes failed on 4 out of the 6 most recent merged PRs (#29164, #29153, #29138, #29104 all have it). All 56 other lanes pass.
Code-side everything looks green. Will ping a maintainer to get this re-triggered or reviewed so it can land. Once it's in a release build, please give it another spin against your original repro!
Still reproduces on Bun 1.4.2: bun build ./index.ts --target node --format cjs --no-bundle prints the import/export statements unchanged and exits 0.
The earlier fix (#29190) was against the Zig sources and never landed. New fix against the current tree: #41988. With it, --no-bundle --format cjs converts each file on its own and keeps every import as a require() of the same specifier:
Activity
robobun commentedon Apr 11, 2026
✅ Reproduced. Fix in #29190 —
--format cjs --no-bundlenow routes ESM imports/exports through the CommonJS printer. Coversexport function/class,export const/let/var(incl. nested destructuring),export default,export * from,export { ... } from, and ES2022 string-literal export names.fix(transpiler): honor --format cjs with --no-bundle
robobun commentedon Apr 11, 2026
Thanks for testing! The previous commits handled every
exportform but I'd missed thes_importhandler entirely — it was still emitting rawimportstatements regardless of format. Fixed in b7924a1: the--no-bundle --format cjspath now rewritesimporttorequiretoo (simple destructuring, no runtime helpers). Could you rebuild and retest? The new output for your example should be:CosmoCreeper commentedon Apr 11, 2026
Nice job! Can confirm that it's working perfectly now!
Not sure why you commented here when I replied in the pull request though. Regardless it looks good.
robobun commentedon Apr 11, 2026
Thanks — that's exactly it.
printCommonJSwas using aNoOpRenamerunconditionally because historically it was only called from the bundler path (after the linker had already run). On the new no-bundle path the parser runs withminify_identifierson but never gets a renamer. Fixed in 451c9ba: mirroredprintAst"'sMinifyRenamer" setup inprintCommonJS", and updatedprintBundledExportsForBinding" to readsymbol.original_name" for theObject.defineProperty" key (external contract) and `renamer.nameForSymbol(ref)" for the getter target (local), so only the local binding shrinks under minify.robobun commentedon Apr 14, 2026
Thanks for digging through the log! Yeah that confirms what I suspected —
env: bun: No such file or directory/ci-remap server did not start: code 127is CI agent setup failing to findbunin `PATH" on the darwin-aarch64 runner. Nothing to do with this PR's code: the same pair of darwin-aarch64 lanes failed on 4 out of the 6 most recent merged PRs (#29164, #29153, #29138, #29104 all have it). All 56 other lanes pass.Code-side everything looks green. Will ping a maintainer to get this re-triggered or reviewed so it can land. Once it's in a release build, please give it another spin against your original repro!
fix(transpiler): honor --format cjs with --no-bundle
robobun commentedon Sep 8, 2026
Still reproduces on Bun 1.4.2:
bun build ./index.ts --target node --format cjs --no-bundleprints theimport/exportstatements unchanged and exits 0.The earlier fix (#29190) was against the Zig sources and never landed. New fix against the current tree: #41988. With it,
--no-bundle --format cjsconverts each file on its own and keeps every import as arequire()of the same specifier:(plus the usual
__export/module.exports = __toCommonJS(...)preamble, the same shape esbuild emits for--format=cjswithout--bundle).