stereobooster / react-snap

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

SyntaxError: Unexpected token '?' #577

Open bykiandra opened 5 months ago

bykiandra commented 5 months ago

Bug Report

Current Behavior I get the following error when I run npm run postbuild:

> react-snap

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

✅  crawled 1 out of 1 (/)

I am trying to deploy the website on Netlify (it's currently live, building from an earlier commit here: https://bykiandra.netlify.app). However, Netlify can't build from any commit where the postbuild script exists.

I've tried looking for the error, but there's nothing amiss in my index.html file, and there are no errors in the console when I build and run my website locally.

Reproducible demo Repo: https://github.com/bykiandra/home-bykiandra

Expected behavior/code I'm expecting the script to run with no errors, and for Netlify to be able to build and host the website without any issue.

Possible Solution I've gone through the other issues and tried some suggestions here and there, but nothing's worked so far. I'll continue fiddling and see if I can find a solution myself.

OmarAbdo commented 4 months ago

Same exact issue here, I found that adding "homepage": ".", to the root level of your package.json file will bypass the error. I don't think it's fixing the error completely because this allows react-snap to generate the HTML pages you'd expect but they are not rendered (all of them would have the same content as the default index.html page before rendering)

TotalChris commented 4 months ago

Lol this did not work for me. Using react-router & Vite. This fix passed the syntax error but only rendered my root page. Any documentation where I can define my routes statically? Does this even work with react-router? Should I join the masses and move to Next.js? Am I real?

(Of course I'm aware that this package isn't actively maintained and I don't expect anyone to have these answers. Simply joking.)

brandonburkett commented 3 months ago

I hit this on a really old project and traced it to a google maps iframe embed URL (that had a question mark). Setting the following config helped me:

  "reactSnap": {
    "skipThirdPartyRequests": true,
    "preconnectThirdParty": false
  }
ashu-dev-ops commented 3 months ago

@brandonburkett did you find any solution ??

miguelcaravantes commented 3 months ago

same issue with the question mark

VasileStelian commented 2 months ago

I have fixed that issue by changing the
"reactSnap": { "source": "/", }, But then i get this : Failed to load module script: The server responded with a non-JavaScript MIME type of "text/jsx".

VasileStelian commented 2 months ago

I guess it's an issue from using vite with react, I've recreated my project with plain create-react-app and it starts crawling the pages as intended with warnings. When trying to deploy it on vercel It fails to launch chrome tho.

NguyenTrongPhuc1804 commented 2 months ago

I'm also having this problem and I don't have a solution yet, I'm really tired

amanix007 commented 2 weeks ago

Anyone found solution for this ?

RaviCodin commented 1 week ago

give me solution plz

amanix007 commented 1 week ago

give me solution plz @RaviCodin https://github.com/amanix007/react-snap check my repo, and fork if needed see if its helpful for your case.