Skip to content

fix: use named import for @babel/generator to fix bundled codegen crash#477

Merged
danadajian merged 1 commit intomainfrom
fix/babel-generator-named-import
May 5, 2026
Merged

fix: use named import for @babel/generator to fix bundled codegen crash#477
danadajian merged 1 commit intomainfrom
fix/babel-generator-named-import

Conversation

@danadajian
Copy link
Copy Markdown
Contributor

Summary

  • @babel/generator exports its generate function as both a default and named export. When bundled with rolldown (via tsdown), default imports go through an __toESM helper with isNodeMode=1, which sets .default to the entire exports object rather than the actual function — causing TypeError: (0, import_lib$2.default) is not a function at runtime.
  • Switching all three call sites from a default import to the named { generate } import avoids this code path and resolves the crash.
  • The CLI CI job previously ran from TypeScript source via bun src/cli.ts, which bypasses the bundler entirely. It has been updated to run from the built dist/cli.mjs so bundler regressions like this are caught before release.

Changes

  • Codegen no longer crashes when run from the published npm package
  • The CLI CI job now exercises the built artifact rather than the raw TypeScript source

Test plan

  • bun run build completes without errors
  • bun dist/cli.mjs --testingType e2e outputs Codegen complete!
  • bun dist/cli.mjs --testingType component outputs Codegen complete!
  • CI cli job passes end-to-end

Generated with Claude Code

The rolldown bundler calls __toESM with isNodeMode=1 for default imports,
which sets .default to the entire exports object rather than the actual
generate function. Switching to the named export avoids this path and
resolves the TypeError at runtime.

Also updates the CLI CI job to run the built dist artifact instead of
the TypeScript source directly, so this class of bundler regression is
caught before release.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danadajian danadajian merged commit e6f0946 into main May 5, 2026
4 checks passed
@danadajian danadajian deleted the fix/babel-generator-named-import branch May 5, 2026 17:27
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

🎉 This PR is included in version 2.5.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant