Repository navigation
fix(build): mark tsdown ESM output as ES modules - #1790
Merged
Merged
Conversation
…solve exports Co-Authored-By: Konstantin Wohlwend <[email protected]>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📝 WalkthroughWalkthroughThe tsdown JavaScript library configuration recursively rewrites package exports for ESM output and adds a bundle-write plugin that creates an ChangesESM build marking
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Konstantin Wohlwend <[email protected]>
This branch had an error being deployed
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.
Problem
The published
@hexclave/*packages emit their ESM build intodist/esm/*.jsand point the exports-mapimportcondition there, but neither the package root nordist/esm/carries a"type": "module"marker. So.jsfiles underdist/esm/default to CommonJS.Strict runtimes (tsx / esbuild loader, older Node) then parse the ESM output as CJS, fail to find the ESM named exports, and throw
SyntaxError: The requested module '@hexclave/js' does not provide an export named 'HexclaveServerApp'(orERR_MODULE_NOT_FOUND). Plain Node >=20.19/22 papers over it via automatic ESM syntax detection, so it only surfaces for ESM consumers ("type": "module") run under tsx — a common scaffold setup. The misleading error sends people chasing renamed-export / resolution rabbit holes.Fix
js-library.tsnow emits adist/esm/package.json={"type":"module"}at build time (a rolldownwriteBundlehook keyed on the ESM output dir). This scopes only the ESM output as ESM; Node/tsx find that nestedpackage.jsonbefore the root one, sodist/*.jsstays CommonJS forrequire()consumers.Applies to every package built through the shared tsdown config (js, next, react, tanstack-start, shared, ui, sc, shared-backend, dashboard-ui-components) — a per-package fix would just move the error one dependency deeper.
Validation
Reproduced against a freshly built
dist, consumed from an ESM project via tsx: before, the SyntaxError above; after,loaded: function. Confirmed the marker lands indist/esm/package.jsononly, never in the CJSdist/root.Link to Devin session: https://app.devin.ai/sessions/637056927f8642fbb51e512ac6caa93b
Requested by: @N2D4
Summary by cubic
Mark ESM outputs as ES modules by writing a nested
package.jsonindist/esmwithtype: "module"and ESM-onlyexports. This fixes broken named exports for ESM consumers (e.g.tsx) in@hexclave/*packages.writeBundlehook inconfigs/tsdown/js-library.tsto emitdist/esm/package.jsonand preserve self-referencing ESM exports (dropsrequiretargets, rewrites paths).dist/behavior forrequire()and applies to all packages using the sharedtsdownconfig.Written for commit a97685c. Summary will update on new commits.
Summary by CodeRabbit
dist/esmpackage metadata is correctly marked as JavaScript modules.exportsso the correct module targets are exposed and CommonJS conditions are omitted.