Fix browser compatibility for @xmcl/system by adding exports field #322
+16
−8
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.
This PR fixes browser compatibility issues with the
@xmcl/systempackage when used with modern bundlers like Vite.Problem
Users were getting compilation errors when trying to use
@xmcl/systemin browser environments:Root Cause
The package already had browser-compatible builds (
index.browser.ts→dist/index.browser.mjs) that use JSZip instead of Node.jsfsAPIs. However, modern bundlers like Vite weren't using the browser build because the package.json lacked the modernexportsfield for conditional exports.Without
exports, bundlers fell back to themodulefield which pointed to the Node.js ESM build (dist/index.mjs) containingfsimports.Solution
Added an
exportsfield topackages/system/package.jsonwith conditional exports:This tells bundlers:
./dist/index.browser.mjs(JSZip-based, no Node.js APIs)./dist/index.mjs(Node.js fs APIs)./dist/index.js(Node.js fs APIs)Testing
Now when users import
@xmcl/systemin Vite or other browser bundlers, they'll automatically get the browser-compatible build instead of the Node.js version.Fixes #307.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.