Conversation
The `browser` field pointed to the CommonJS build, so browser-targeting bundlers resolved `dist/cjs/index.js` and could mis-handle its default export interop (e.g. Rolldown's `import_cjs.default is not a function`). Point `browser` at the ESM build and add an `exports` map so modern resolvers use the ESM build for `import`/browser and the CJS build for `require`. Note: adding `exports` encapsulates the package, so deep imports such as `react-element-to-jsx-string/dist/cjs/index.js` are no longer available.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
TIP This summary will be updated as you push new changes.
rbardini
marked this pull request as ready for review
September 15, 2026 00:36
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
The
browserfield points to the CommonJS build (dist/cjs/index.js). Browser-targeting bundlers that readbrowsertherefore resolve the CJS build, which can break default-export interop. For example, building a Storybook 11 addon with Vite/Rolldown that imports this package throws:and, once the CJS build is inlined, its
require('react')becomes a runtimerequirethat fails in the browser:Relates to rbardini/storybook-addon-playroom#88.
Change
browserat the ESM build (dist/esm/index.js).exportsmap so modern resolvers use the ESM build forimport/browser and the CJS build forrequire, while keepingmain/module/typesfor older tooling.Note
Adding
exportsencapsulates the package: deep imports such asreact-element-to-jsx-string/dist/cjs/index.jswill no longer resolve. Happy to expose those subpaths if you consider them part of the public API.Verification
Resolution checked locally with Node (no build changes needed):
require('react-element-to-jsx-string')→dist/cjs/index.jsimport 'react-element-to-jsx-string'→dist/esm/index.jsimportwith--conditions=browser→dist/esm/index.jsrequire('react-element-to-jsx-string/package.json')→ resolvesmoduleResolution: nodenext) resolvesindex.d.ts