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: there is no renderToReadableStream function in react-dom@18.2.0 in Node.js #26906

Open
krutoo opened this issue Jun 6, 2023 · 8 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@krutoo
Copy link

krutoo commented Jun 6, 2023

I try to use renderToReadableStream function from react-dom/server in Node.js but there is no such function in package.

React version: 18.2.0
Node.js version 16.15.0 or 18.16.0

Steps To Reproduce

  1. create index.mjs file
  2. insert code:
    import { renderToString, renderToReadableStream } from "react-dom/server";
    
    console.log({ renderToString, renderToReadableStream });
  3. run node index.mjs in terminal

Link to code example:

StackBlitz

The current behavior

Error in terminal:

file:///Users/user/Projects/node-fetch-api-server/index.mjs:1
import { renderToString, renderToReadableStream } from "react-dom/server";
                         ^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'renderToReadableStream' not found. The requested module 'react-dom/server' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-dom/server';
const { renderToString, renderToReadableStream } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.16.0

The expected behavior

Node.js suupports web streams in experimental mode.

The package react-dom/server must have a function renderToReadableStream according to the documentation:
https://react.dev/reference/react-dom/server/renderToReadableStream

@krutoo krutoo added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jun 6, 2023
@krutoo krutoo changed the title Bug: Bug: there is no renderToReadableStream function in react-dom/server in Node.js Jun 6, 2023
@krutoo krutoo changed the title Bug: there is no renderToReadableStream function in react-dom/server in Node.js Bug: there is no renderToReadableStream function in react-dom@18.2.0 in Node.js Jun 6, 2023
@MeenuyD
Copy link

MeenuyD commented Jun 6, 2023

Hello I think this is not the bug in React-dom I have checked both the official documentation repository there are mentions about the reanderToReadableStream there you wrote an incorrect code here is the updated code.

import ReactDOMServer from 'react-dom/server;

const { renderToString, renderToReadableStream } = ReactDOMServer;

console.log({ renderToString, renderToReadableStream });

because the error says that it is the syntax error Named export 'renderToReadableStream' not found. The requested module 'react-dom/server' is a CommonJS module, which may not support all module.exports as named exports.

@krutoo
Copy link
Author

krutoo commented Jun 6, 2023

@MeenuyD I tried your snippet and it doesn't work either

@thynson
Copy link

thynson commented Jun 14, 2023

Node.js exposes WebStream to global since 18.+, but react-dom/server does not export renderToReadableStream without checking if it present.

@krutoo
Copy link
Author

krutoo commented Jun 14, 2023

Is it possible to add renderToReadableStream to Node.js package?

@marbemac
Copy link

Ditto - often when building and testing things locally the runtime is node, while the final deploy target is edge (cloudflare, etc). Because renderToReadableStream is not exposed on the node build, we have to do a dance to make everything work.

Any particular reason to not include renderToReadableStream on the node build? Made sense when node did not have support for web streams, but it has for a while now, and now that everybody seems to be converging on the web streams standard perhaps it makes more sense to include?

Copy link

github-actions bot commented Apr 9, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 9, 2024
@marbemac
Copy link

marbemac commented Apr 9, 2024

bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
@ondrej-langr
Copy link

Bump, there is no export from the ./server.node.js file. Is there a reason for it?

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

5 participants