Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug [React-DOM]: Missing "bun" export field in package.json #28941

Closed
Guibi1 opened this issue Apr 28, 2024 · 3 comments
Closed

Bug [React-DOM]: Missing "bun" export field in package.json #28941

Guibi1 opened this issue Apr 28, 2024 · 3 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@Guibi1
Copy link

Guibi1 commented Apr 28, 2024

In the exports field of the react-dom's package.json, there is no "bun" field. Bun defaults to the "default" field for compatibility. However, the ./server.node.js file doesn't export renderToReadableStream(), while Bun supports Web Streams out of the box.

See: The Bun doc on Module resolution
This issue is similar to #26906, but Bun always supported Web Streams so there is no backwards compatibility issues.

React version: 18.3.1

Steps To Reproduce

  1. Install react-dom.
  2. Import renderToReadableStream()
  3. Run the file using Bun
  4. Notice that the error is something like this: SyntaxError: Export named 'renderToReadableStream' not found in module '~/??/node_modules/react-dom/server.node.js'., which clearly shows that Bun uses the default export.

Link to code example:
I am not sure how to use Bun on the browser.

The current behavior

Bun uses the default export. (aka server.node.js)

The expected behavior

Bun uses a custom "bun" export. (aka server.browser.js)

I have tested the following change locally and it completely fixes this issue:

fixed package.json

@Guibi1 Guibi1 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 28, 2024
@AldoMX
Copy link

AldoMX commented May 1, 2024

The issue is fixed in react-dom v19, and taking a closer look they created new configuration files for bun:
https://github.com/facebook/react/blob/main/packages/react-dom/package.json#L63

I'm not sure how willing would be the team to merge my PR with your suggested fix for v18, but let's wish for the best 🤞:
#28962

@Guibi1
Copy link
Author

Guibi1 commented May 1, 2024

Oh nice I'll upgrade to react-dom@next then. I would be useful to merge your PR, just for compatibility.

@gnoff
Copy link
Collaborator

gnoff commented May 1, 2024

@Guibi1 for React 18 you can always just import the right version yourself if you know you are using bun. import ... from "react-dom/server.browser"

I don't think we'll do another 18 release with this but React 19 should support it. If bun also supported running with custom conditions you could potentially customize the resolution that way but I don't think it supports that right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants