Reputation: 4418
My ReactJs application runs fine on my local box, when I use the npm start
command. However when I try to deploy my application using the firebase init
to Firebase, I am seeing a blank page. What could I be doing wrong?
Update: I had to edit the Firebase.json file to remove the
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"],
line as I was getting errors related to that.
Firebase.json:
{
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
Firebase deploy command output:
=== Deploying to 'socialmedia-5ec0a'...
i deploying database, storage, firestore, functions, hosting
i database: checking rules syntax...
+ database: rules syntax for database socialmedia-5ec0a is valid
i storage: checking storage.rules for compilation errors...
+ storage: rules file storage.rules compiled successfully
i firestore: checking firestore.rules for compilation errors...
+ firestore: rules file firestore.rules compiled successfully
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i storage: uploading rules storage.rules...
i firestore: uploading rules firestore.rules...
i functions: preparing functions directory for uploading...
i hosting[socialmedia-5ec0a]: beginning deploy...
i hosting[socialmedia-5ec0a]: found 5 files in public
+ hosting[socialmedia-5ec0a]: file upload complete
i database: releasing rules...
+ database: rules for database socialmedia-5ec0a released successfully
+ storage: released rules storage.rules to firebase.storage/socialmedia-5ec0a.appspot.com
+ firestore: released rules firestore.rules to cloud.firestore
i hosting[socialmedia-5ec0a]: finalizing version...
+ hosting[socialmedia-5ec0a]: version finalized
i hosting[socialmedia-5ec0a]: releasing new version...
+ hosting[socialmedia-5ec0a]: release complete
+ Deploy complete!
Project Console: https://console.firebase.google.com/project/socialmedia-5ec0a/overview
Hosting URL: https://socialmedia-5ec0a.firebaseapp.com
Upvotes: 37
Views: 35326
Reputation: 421
In my case I have a VueJs3 (Vite) SPA app and the solution was to add the base property to my vite.config.js
export default defineConfig({
plugins: [vue()],
base: './'
});
Upvotes: 0
Reputation: 69
To solve the issue, follow these steps:
<div id="root"></div>
.<script defer="defer" src="./static/js/main.36b3b093.js"></script>
src
path according to your desired folder structure for the main.36b3b093.js file. Normally, it is located under the static folder within a subfolder named js.Upvotes: 0
Reputation: 53
I found that firebase hosting requires some time to get all your website running. For me, it takes up to ~30 minutes for the first time it uploads. Subsequent updates should upload in an instant.
If you notice in the inspector developer tools, that only the html page is active and not the rest of the page, then this might be the solution.
So my advice is just to be patient and grab a cup of coffee :)
Upvotes: 4
Reputation: 171
Just remove homepage
key from the package.json file if you deployed it to GitHub also.
It worked for me hope so for you as well.
Upvotes: 3
Reputation: 168
Upvotes: 6
Reputation: 1
use build to build
{
"hosting": {
"build": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Upvotes: -1
Reputation: 11
I had the the same problem. But after the build folder was pointed to. . . I was still seeing a blank host. In this case what you can do is copy the build folder which contains the firebase init code, and paste it into the public folder. Make sure that you add in your <div id=root> </div>
into the body section, then npm run build
again. Make sure also that your firebase.json is pointing to build as mentioned in earlier posts.
Upvotes: 1
Reputation: 15908
After you have initialized your Firebase application with firebase init
, you should have a firebase.json file in your project's folder. The thing is that the public key has to point to your build folder. For instance, in create-react-app the build folder is build/ after you have ran npm run build for the first time. Then the firebase.json has to look similar to this one:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
The public key points to build. Then try another deploy with firebase deploy
.
Upvotes: 20
Reputation: 239
100% Working Example.
Solved Blank Page Error in React App Hosting in Firebase .
Found solution in this blog
Host Your React Web App in few minutes.
Wrong sequence =>
firebase login
firbase init
firebase deploy
npm run build
Correct sequence =>
firebase login
firbase init
npm run build
firebase deploy
Upvotes: -5
Reputation: 1
If changing the 'public' property in the firebase.json doesn't work then first find out in which folder is your index.html file, make sure it's the index.html that you wrote, cause firebase might put a mock index.html in the main folder and move your index.html in a 'build' folder, it might also have another folder with the name of your app inside the 'build' folder. Then you need to change the 'public' property in the firebase.json to the name of that folder, like this:
{
"hosting": {
"public": "my-app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Upvotes: 0
Reputation: 680
Check you don't have the homepage
property set inside package.json. I had it because I was also deploying to Github pages at first. Removed it, rebuilt, redeployed and worked.
Upvotes: 11
Reputation: 81
Another thing you might also check if changing the firebase.json
file does not work.
Application->Clear Storage
clean site data
refresh
the app.In some cases, it works.
Upvotes: 8
Reputation: 786
I was having the same problem. http://localhost:3000/ was serving the app well but when I deployed using npm run build
and then firebase deploy
I was just seeing a blank page.
I am not sure of the reason why, but I changed the 'public" property in the firebase.json to "build" and it worked.
here is my new firebase.json document.
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Upvotes: 69
Reputation: 70436
Have a look at the public
property of you package.json
"public": "public",
It points to the resource folder where firebase hosting will look for your application. If the resource folder is empty, you will be presented with a blank page
When you build your react app, all the files go to the build
folder by default, if you have not specified otherwise. So set the public property to your reactjs build folder.
Upvotes: 14