fix(esm): bundle ESM/CJS builds to avoid Node ESM resolution issues in SSR#403
Conversation
4a57d06 to
b934988
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 15
Lines 414 391 -23
Branches 156 174 +18
=========================================
- Hits 414 391 -23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @jontas Thanks for this PR, I did not notice this when I change the build config oops. Changing Does this work for you? If so, I'd prefer keeping the build config the same and only changing the one line. |
b934988 to
fda771d
Compare
|
@cchanxzy Thanks for taking a look! I removed a few changes but the current commit has the minimal changeset that worked for me. At first it seemed like changing platform to The If you have other suggestions I'm happy to give them a try 🙏 |
|
🎉 This PR is included in version 4.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Thanks @jontas for this! I was experimenting and seeing if it could work without bundling, but seems like bundling was the only way. Merged now, thanks for your contribution! And spotting the issue and fixing too :) |
|
🥳 thank you! |
Summary
This PR updates the build to emit single-file bundles for both ESM and CJS. It removes extensionless internal imports from the ESM output that break SSR under Node’s ESM resolver.
The published ESM entry
dist/esm/index.jspreviously referenced internal files using extensionless relative imports (e.g.,./components/CurrencyInput). When a dev SSR tool (e.g., Vite with React Router) externalizes the package, Node tries to resolve those imports directly and fails because Node ESM requires explicit file extensions.This surfaced as: “Cannot find module .../dist/esm/components/CurrencyInput imported from .../dist/esm/index.js”.
Solution
Minimal Reproduction
npx create react-router@latestpnpm add react-currency-input-field@4.0.1import CurrencyInput from 'react-currency-input-field'<CurrencyImport>component somewhere on the pagepnpm dev