i was trying to deploy my react SPA on Firebase, but got only blank page with such console error: "Uncaught SyntaxError: Unexpected token <"
chrome console chrome_elements_blank
to exclude third part libraries I created new React-app to deploy. and got exactly same problem.
terminal log:
part1 part2
part3 part4
anybody knows how to fix this?
link to firebase deployed create-react-app start page
Code from firebase.json
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source" : "*",
"destination" : "/index.html"
}
]
}
}
Choose hosting: Configure files for Firebase hosting and (optionally) set up GitHub Action deploys. Use an existing project: Select the Firebase project you created earlier ( react-app-firebase ). Enter build as the public directory. Configure as a single-page app: Yes .
Your React App may be hosted in three easy steps. Render comes with a free SSL certificate, a global CDN, a custom domain, and auto-deployment with Git integration. Render offers a free static site hosting plan as well as competitive pricing for other services.
Your main.js contains the page html data again.
<!doctype html><html lang="en"><head>...
.
As the browser loads the JS file and tries to interpret it, it fails, as HTML is clearly not javascript. It tries to communicate its confusion with "Oh I found a < but that is not what I expected".
You seem to have configured a default route for your server and each and any request returns your index.html.
I noticed in one of your screenshots, that you said "yes" to "Rewrite all urls to index.html" - it does exactly that. You should not activate that, as ALL you requests will then always return the index.html
.
Please have a look in your firebase.json
file. You will find the instructions for hosting and routing in there.
API Docs are here:
https://firebase.google.com/docs/hosting/full-config
You might want to have a special look into the redirects array, looking like this:
"redirects": [
{
"source" : "*",
"destination" : "/index.html"
}
]
Here you tell the server to redirect all traffic to /index.html
. Delete the redirect entries, redeploy and all will be well.
So this redirects section will most probably solve the issue:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": []
}
}
This also can be an issue in the package.json
file, if you have set the attribute homepage
{
"name": "project-name",
"homepage": "https://project-url",
"version": "0.1.0",
}
to solve this issue remove the homepage
attribute.
thanks everyone for quick reply. problem was solved with adding "redirects":[]
to firebase.json like this:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With