Skip to content

fix: resolve @babel/traverse CJS/ESM interop for native .mts execution#590

Merged
John-David Dalton (jdalton) merged 3 commits intomainfrom
fix/babel-traverse-esm-interop
Apr 16, 2026
Merged

fix: resolve @babel/traverse CJS/ESM interop for native .mts execution#590
John-David Dalton (jdalton) merged 3 commits intomainfrom
fix/babel-traverse-esm-interop

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

Summary

  • Fix traverse is not a function error in generate-sdk.mts by correctly resolving the CJS/ESM double-default interop issue with @babel/traverse
  • Bump .node-version to 25.9.0

Details

Node's ESM loader wraps CJS modules so import traverse from '@babel/traverse' gives a namespace object (not the function). The actual traverse function is at .default on that object. The previous fix (#589) used import { default as traverse } which is semantically identical to import traverse in ESM — both resolve to the namespace object.

Test plan

  • pnpm test passes (TypeScript check + lint + tests)
  • node scripts/generate-sdk.mts runs successfully end-to-end
  • Verified with standalone script that _traverse.default is the callable function

Node's ESM loader wraps CJS modules so the default export is a namespace
object, not the function itself. Extract `.default` at runtime with a
cast to satisfy TypeScript. Also bump .node-version to 25.9.0.
Apply the same runtime-safe interop resolution in both generate-sdk.mts
and bundle-validation.test.mts. The typeof check handles both Vitest
(where the import may already be the function) and native Node ESM
(where it's wrapped under .default).
@jdalton John-David Dalton (jdalton) merged commit 9d885fa into main Apr 16, 2026
11 checks passed
@jdalton John-David Dalton (jdalton) deleted the fix/babel-traverse-esm-interop branch April 16, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants