Search code examples
reactjsfirebasefirebase-hosting

Trying to deploy a ReactJS project using FirebaseCLI


I have a ReactJS app I built that works locally , I followed the instructions on the Firebase site

https://medium.com/@devesu/host-a-react-based-website-free-of-cost-with-firebase-hosting-and-connect-with-your-own-domain-53146731807f

and everything went to plan ,inthat there were no errors however when I follow the link provided

https://hydrometric-54ec0.web.app

or

https://hydrometric-54ec0.firebaseapp.com/

I get a default Firebase page and not my app, I think my firebase.json is missing something here it is below

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

Solution

  • If you are deploying any React project in Firebase. look for the below steps.

    • Once the react build is done through npm run build
    • Do firebase init
    • Select Hosting
    • Then CLI will ask for public directory- Write build and hit enter.
    • rewrite all urls to /index.html- Type Yes
    • File build/index.html already exists. Overwrite?- Type No or else it will overwrite your index file with firebase default index.

    Before firebase deploy do the following things. Replace this code in firebase.json

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

    Then inside your react package.json do blank path for homepage

    • "homepage": ""

    Now yor are good to go for firebase deploy