fix: resolve @babel/traverse CJS/ESM interop for native .mts execution#590
Merged
John-David Dalton (jdalton) merged 3 commits intomainfrom Apr 16, 2026
Merged
Conversation
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).
Trevor Norris (trevnorris)
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
traverse is not a functionerror ingenerate-sdk.mtsby correctly resolving the CJS/ESM double-default interop issue with@babel/traverse.node-versionto 25.9.0Details
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.defaulton that object. The previous fix (#589) usedimport { default as traverse }which is semantically identical toimport traversein ESM — both resolve to the namespace object.Test plan
pnpm testpasses (TypeScript check + lint + tests)node scripts/generate-sdk.mtsruns successfully end-to-end_traverse.defaultis the callable function