cereallarceny / cra-ssr

[DEPRECATED] Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk
484 stars 118 forks source link

console.log doesn't work server-side #23

Closed jtorjo closed 6 years ago

jtorjo commented 6 years ago

First off, I'm a noob with server-side React, so I may look like an idiot. But that's ok - I just want to know how to have the console.log statements show up :)

Environment

Environment: OS: Windows 10 Node: 8.11.3 Yarn: Not Found npm: 6.4.1 Watchman: Not Found Xcode: N/A Android Studio: Not Found

Packages: (wanted => installed) react: ^16.4.0 => 16.5.0 react-dom: ^16.4.0 => 16.5.0 react-scripts: 1.1.4 => 1.1.4

Steps to Reproduce

  1. Download my web app from here -> https://www.dropbox.com/s/9da2sr9crztf3p9/cra-works.zip?dl=0 I've done my best to keep this as minimal as possible. Note - just using your full example, you'll see that in the npm console, nothing gets printed. For instance: Loadable.preloadAll().then(() => { app.listen(PORT, console.log(App listening on port ${PORT}!)); }); This doesn't get shown anywhere.

  2. npm install && npm start
    This will open localhost:3000 (with express)

Expected Behavior

When "/" is rendered server side, there are several console.log messages in the "server/*" that should happen on the server -> and should be outputted to the npm console.

Actual Behavior

None of the console.log statements are outputted to the npm console.

james-lukensow commented 6 years ago

Took a quick glance, you won't see your server console.log until you run it with SSR. Right now, with yarn start, runs the app without SSR.

jtorjo commented 6 years ago

@whnunlife Thanks for trying!

I tried this, but since I don't have yarn, I did it with npm: npm run build serve -s build

It still doesn't work.

Do I need to use yarn specifically?

james-lukensow commented 6 years ago

Nah, will work without yarn.

Try this:

npm run build && npm run serve

jtorjo commented 6 years ago

Works like a charm! The reason I didn't do this initially was because NODE_ENV=production node ./server/index.js generates an error on windows. Worked around that, and it's all good. Thanks!