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

[react-dom][18.3.1] Add bun export to react-dom. #28962

Closed
wants to merge 1 commit into from

Conversation

AldoMX
Copy link

@AldoMX AldoMX commented May 1, 2024

Summary

When you try to bun run a project that uses renderToReadableStream from react-dom, you get the following error:

1 | (function (entry, fetcher)
    ^
SyntaxError: Export named 'renderToReadableStream' not found in module '/path/to/node_modules/react-dom/server.node.js'.
1 | (function (entry, fetcher)
    ^
SyntaxError: Export named 'renderToReadableStream' not found in module '/path/to/node_modules/react-dom/server.node.js'.

In #28941 it was reported that adding a "bun": "./server.browser.js", export to the package.json fixes the issue.

How did you test this change?

Screenshot with a run before and after the fix:
image

@AldoMX AldoMX changed the title Add bun to react-dom's package.json. [react-dom][18.3.1] Add bun to react-dom's package.json. May 1, 2024
@AldoMX AldoMX changed the title [react-dom][18.3.1] Add bun to react-dom's package.json. [react-dom][18.3.1] Add bun export to react-dom. May 1, 2024
@gnoff
Copy link
Collaborator

gnoff commented May 1, 2024

Thanks for the suggestion however we released 18.3 to add additional warnings to help with upgrading to 19 and don't plan to include any changes to functionality or packaging from what was supported in 18.2.

You can always directly import the specific runtime you want to load with a specifier like require("react-dom/server.browser") so you should be able to load the desired version when using bun with some effort.

React 19 adds bun conditions so this should already be resolved when that version is released

@gnoff gnoff closed this May 1, 2024
@AldoMX
Copy link
Author

AldoMX commented May 3, 2024

I'd still ask to reconsider, considering v18 is still the latest stable version, and we're months away from v19 stable.


I'm leaving my TypeScript notes as reference to anyone who reaches this dead-end:

Update imports:

// from
import { renderToReadableStream } from 'react-dom/server';

// to
import { renderToReadableStream } from 'react-dom/server.browser';

Add to your global definition file (ex. global.d.ts):

declare module 'react-dom/server.browser' {
  import * as ReactDOMServer from 'react-dom/server';
  export = ReactDOMServer;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants