web: add default export to CJS bundle#5305
Merged
amaanq merged 1 commit intotree-sitter:masterfrom Feb 10, 2026
Merged
Conversation
Why? ==== The CJS bundle sets __esModule: true and exports named members (Parser, Language, etc.) but has no .default property. When TypeScript consumers use module: "commonjs" + esModuleInterop: true, the __importDefault helper sees __esModule and returns module.default — which is undefined. This causes `import Parser from 'web-tree-sitter'` to silently resolve to undefined at runtime despite typechecking cleanly. Reproduction: https://github.com/chadxz/web-tree-sitter-default-export-type-issue How? ==== - Traced the issue by inspecting the CJS bundle output and confirming __esModule is set but no .default exists - Added `module.exports.default = module.exports;` via esbuild's footer option, conditionally for CJS builds only - Verified by patching the published 0.26.3 bundle in a repro project and confirming the default import resolves correctly - Built the full ESM + CJS bundles from source to confirm the footer appears in the CJS output and the .d.cts types align
Contributor
Author
|
@WillLillis @clason is this something you'd be interested in merging? Any other validation you'd like to see? |
WillLillis
approved these changes
Feb 10, 2026
|
Successfully created backport PR for |
Contributor
Author
|
Thanks all! 🙌 |
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.
Why?
The CJS bundle sets __esModule: true and exports named members
(Parser, Language, etc.) but has no .default property. When
TypeScript consumers use module: "commonjs" + esModuleInterop:
true, the __importDefault helper sees __esModule and returns
module.default — which is undefined. This causes
import Parser from 'web-tree-sitter'to silently resolve toundefined at runtime despite typechecking cleanly.
Reproduction: https://github.com/chadxz/web-tree-sitter-default-export-type-issue
How?
confirming __esModule is set but no .default exists
module.exports.default = module.exports;viaesbuild's footer option, conditionally for CJS builds only
project and confirming the default import resolves correctly
footer appears in the CJS output and the .d.cts types align