0

I have a ReactJS project that uses Firebase for the back-end and I used Firebase Hosting to host it, at first it worked and everything seemed fine but when I tried to access the app 1 hour later it is blank. In windows browser it doesn't show any error in console but on Ubuntu VM is says Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key).

When I saw that I tried running the project locally but it works fine, no such error appears. The dotenv file where I store the key hasn't been changed at all and the fact that it runs locally really throws me off and I can't understand why this error occurs. Is it something regarding deployment? I also activated the GitHub actions but I deployed the app using npm run build and firebase deploy, dunno if it matters but maybe might be a hint. Also this is the firebase.json file:

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
bsheps
  • 1,438
  • 1
  • 15
  • 26

1 Answers1

0

I noticed this happens to me when I have Github Actions created to deploy on-commit but also have a .firebase/hosting-*****.cache file which is not yet committed / deployed to the repository.

Try committing and deploying that hosting cache file to see if it resolves the issue.

Otherwise try dropping the .firebase and ./build folders entirely and re-build, commit and deploy again.

Also regarding your firebase.json file, it looks fine.

I hope one of these two suggestions helps!

Wesley LeMahieu
  • 2,296
  • 1
  • 12
  • 8
  • I re-run the build and deploy command and for now it seems to work but I will wait a bit to see if the error occurs again before deleting the .firebase and `./build` folder cause I don't want to run that every time the app crashes. But I'm curious about `.firebase/hosting-****.cache` cause I wonder if I will need some headers in firebase.json file if the error is not fixed after your suggestions. – Valentin-Constantin Baltatescu Feb 08 '23 at 12:53