Blank page after successful Firebase deployment

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

Chrome F12 output:
enter image description here

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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"
      }
    ]
  }
}

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

Another thing you might also check if changing the firebase.json file does not work.

  1. in the Chrome dev tools, go to Application->Clear Storage
  2. click on clean site data
  3. then refresh the app.

In some cases, it works.

Solution 6

  • delete .firebase folder
  • delete your build folder and build it again by "npm run build"
  • Then again initialize your app by "firebase init"
  • What do you want to use as your public directory? build // public directly should be build
  • Configure as a single-page app (rewrite all URLs to /index.html)? Yes // rewrite rules yes
  • Set up automatic builds and deploys with GitHub? (y/N) n // automatic builds no
  • File build/index.html already exists. Overwrite? (y/N) n // should not rewrite the index.html most important part
  • firebase deploy // you are good to go.

Solution 7

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.

Solution 8

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 🙂

Solution 9

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.

Solution 10

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"
          }
        ]
      }
    }

Solution 11

use build to build

{
  "hosting": {
    "build": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Solution 12

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply