stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.04k stars 391 forks source link

Can't resolve 'ws' when using {run} #336

Closed vemundeldegard closed 5 years ago

vemundeldegard commented 5 years ago

Bug Report

Current Behavior Trying to include pages from my CMS into the "include" part of React-snap. Getting this error:

./node_modules/puppeteer/lib/WebSocketTransport.js Module not found: Can't resolve 'ws' in '/Users/vem/gauc/node_modules/puppeteer/lib'

The only code I added was:

import { run } from "react-snap"

run({
  include: ['/', '/kontakt-oss', '/blogg']
})

Reproducible demo Here is a demo https://codesandbox.io/s/zk5w0m5r3l

Expected behavior/code Trying to use react-snap programatically to add routes and make sure that they are crawled.

Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

stereobooster commented 5 years ago

The interesting part is that it is not react-snap fails, it is react-scripts build. I removed all calls of react-snap and it still fails https://codesandbox.io/s/lqryym71m

This seems to be an issue of create-react-app. Also related https://github.com/GoogleChrome/puppeteer/issues/3466

UPD

If I edit ./node_modules/puppeteer/lib/WebSocketTransport.js and add throw new Error() I don't see this error, so file is not executed, it just being parsed by some tool. My guess this is webpack parsing node_modules.

stereobooster commented 5 years ago

Reported in create-react-app https://github.com/facebook/create-react-app/issues/6510

stereobooster commented 5 years ago

I found the error. You need to put this in separate file (script for node) not in the code of web application

import run from "react-snap";

run({
  include: ["/", "/kontakt-oss", "/blogg"]
});
Dathan88 commented 5 years ago

Would you recommend putting it inside the "ws" file?

I'm not using "react-snap" but I'm getting the same errors using puppeteer with CRA.