简体   繁体   中英

ReactDOMServer is not defined

I'm using pre-built browser builds of React and ReactDOM v15 from here since I can't use npm in a given project.

I need to use renderToString from the react-dom/server but I'm getting ReactDOMServer is not defined error.

React and ReactDOM are fine. Any idea how I can access ReactDOMServer ?

Cause you haven't imported it. Add this

import ReactDOMServer from 'react-dom/server';

If react-dom/server not found then you need to npm install it

npm install react react-dom

Actually, after running into this issue myself and trying to find ReactDOMServer somewhere, I almost gave up and was looking for the source directly and about to Browserfiy when like 10 answers down in Google I saw the cdnjs libaries and lo and behold:

https://cdnjs.com/libraries/react/

https://cdnjs.cloudflare.com/ajax/libs/react/15.4.0/react-dom-server.min.js

So I guess they have it built there, and so there you go, you can include it wherever you like, like JSBin as I'm doing.

In my bundles file I had to import:

//= require react-dom/static/react-dom-server

Then I was able to import ReactDOMServer from react-dom/server without a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM