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

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

Open
aakashpgandhi opened this issue Apr 18, 2022 · 11 comments
Open

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

aakashpgandhi opened this issue Apr 18, 2022 · 11 comments

Comments

@aakashpgandhi
Copy link

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
Copy link

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

@stefanoschrs
Copy link

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
Copy link

Silur commented Aug 28, 2023

same issue here with vite

@sbaptista18
Copy link

sbaptista18 commented Jan 2, 2024

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
Copy link

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

@dimonb
Copy link

dimonb commented Jan 25, 2024

same one

react-snap

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

✅ crawled 1 out of 1 (/)

@ashu-dev-ops
Copy link

any solution

@JSpiner
Copy link

JSpiner commented Apr 7, 2024

same here

@djiworks
Copy link

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

@juandiegombr
Copy link

juandiegombr commented Jun 2, 2024

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

  "reactSnap": {
    "source": "public"
  }

@djiworks
Copy link

djiworks commented Jun 2, 2024

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 : vitejs/vite#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests