stereobooster / react-snap

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

pageerror at /: SyntaxError: Unexpected token '.' #557

Open aakashpgandhi opened 2 years ago

aakashpgandhi commented 2 years ago

pageerror at /: SyntaxError: Unexpected token '.' at Object../node_modules/usehooks-ts/dist/esm/useEventListener/useEventListener.js (http://localhost:45678/main.js:14103:1) at webpack_require (http://localhost:45678/main.js:19980:42) at eval (webpack://frontend/./node_modules/usehooks-ts/dist/esm/useEventListener/index.js?:5:75)
at Module../node_modules/usehooks-ts/dist/esm/useEventListener/index.js (http://localhost:45678/main.js:14092:1) at
webpack_require
(http://localhost:45678/main.js:19980:42) at eval (webpack://frontend/./node_modules/usehooks-ts/dist/esm/useClickAnyWhere/useClickAnyWhere.js?:5:75) at Module../node_modules/usehooks-ts/dist/esm/useClickAnyWhere/useClickAnyWhere.js (http://localhost:45678/main.js:13927:1) at __webpack_require__ (http://localhost:45678/main.js:19980:42) at eval (webpack://frontend/./node_modules/usehooks-ts/dist/esm/useClickAnyWhere/index.js?:5:75)
✅ crawled 1 out of 1 (/)

i am getting this error while running npm run postbuild

chrismadufor commented 1 year ago

Hi @aakashpgandhi I am getting a similar error. Have you been able to resolve it?

stefanoschrs commented 1 year ago

Hey @aakashpgandhi @chrismadufor everything was working fine for me for the last year until today that I started getting this error, without any changes to the node version & packages 🤷🏽‍♂️ Did you find any solution?

Silur commented 11 months ago

same issue here with vite

sbaptista18 commented 6 months ago

Hi! Having this error in a React project on a Mac, but it runs just fine in another React project on a Windows. I already checked the dependencies, the code itself, syntax errors, and I found nothing. Any insight on this?

Thanks!

OmarAbdo commented 6 months ago

I'm seeing pageerror at /: SyntaxError: Unexpected token '?' on my react project (With vite & typescript)

dimonb commented 6 months ago

same one

react-snap

🔥 pageerror at /: SyntaxError: Unexpected token '?'

✅ crawled 1 out of 1 (/)

ashu-dev-ops commented 4 months ago

any solution

JSpiner commented 3 months ago

same here

djiworks commented 1 month ago

same for me using vite v4.4.9 and "react": "^18.2.0", "react-router-dom": "^6.16.0"

juandiegombr commented 1 month ago

I had a similar error and I solved it with this configuration in the package.json:

  "reactSnap": {
    "source": "public"
  }
djiworks commented 1 month ago

Hi, on my side, the issue was not directly due to react-snap. I got Unexpected token '?'. Actually this error was a build output issue.

My potential explanation: Vitejs using tsc & vite build was compiling in es6. So in output files in dist folder there was some lines of code containing ?? operator which was not handle by old browser (it was returning Unexpected token '?' because it just understand the normal ? operator. https://stackoverflow.com/questions/65396855/syntaxerror-unexpected-token

However, as react snap is using puppeteer, I think the browser was not able to handle es6. So I try to update the version of puppeteer used by react-snap without success until I found how to force compilation to make output in old es5 files.

I did this to make it work perfectly with vitejs : https://github.com/vitejs/vite/discussions/10519.

PS: I had to test my code on very old iPad using old safari version to be able to found the solution. Once it worked on the device, it was working also with pupeteer. I say this because depending on the error, maybe you can resolve it without changing compilation options and just change the JS notation used (I think about function declaration using =>).

PPS: to better found error source, use await puppeteer.launch({ dumpio: true }); in react-snap source code for testing purpose. This will basically "pipe browser process stdout and stderr into process.stdout and process.stderr", which means it will redirect browser logs to whatever main process, server, etc. you are running.