23

When I am hosting my web page through firebase hosting then after writing command firebase deploy I got the following error:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\amarg\Desktop\amar>firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  C:\Users\amarg\Desktop\amar

Before we get started, keep in mind:

  * You are initializing in an existing Firebase project directory

? Are you ready to proceed? Yes
? What Firebase CLI features do you want to setup for this folder? Hosting: Configure and deploy Firebase Hosting sites


=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

i  .firebaserc already has a default project, skipping

=== Hosting Setup

Your public directory is the folder (relative to your project directory) that
will contain Hosting assets to be uploaded with firebase deploy. If you
have a build process for your assets, use your build's output directory.

? What do you want to use as your public directory? public
? Configure as a single-page app (rewrite all urls to /index.html)? No
? File public/404.html already exists. Overwrite? No
i  Skipping write of public/404.html
? File public/index.html already exists. Overwrite? No
i  Skipping write of public/index.html

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

+  Firebase initialization complete!

C:\Users\amarg\Desktop\amar>firebase deploy

=== Deploying to 'learningweb-6b2a3'...

i  deploying hosting
+  database: rules ready to deploy.
i  hosting: preparing public directory for upload...

Error: An unexpected error has occurred.

C:\Users\amarg\Desktop\amar>
GSerg
  • 76,472
  • 17
  • 159
  • 346
Amarjeet Kumar
  • 231
  • 1
  • 2
  • 3
  • I'd recommend reaching out to Firebase [support](https://firebase.google.com/support/contact/troubleshooting/) and include the output of `firebase deploy --debug` in your message. – Michael Bleigh Feb 27 '17 at 18:34
  • follow this tutorial step by step or watch youtube video on this blog. you will understand everything. http://codingaffairs.blogspot.com/2017/06/how-to-firebase-web-hosting-and-connect.html – Developine Jun 25 '17 at 06:15
  • Check the below solution [https://stackoverflow.com/questions/50360477/angular-6-0-firebase-hosting-deploy-not-working/51809723#51809723](https://stackoverflow.com/questions/50360477/angular-6-0-firebase-hosting-deploy-not-working/51809723#51809723) – bajran Aug 12 '18 at 14:41
  • `npm install -g npm@latest` – Ronnie Royston Apr 15 '19 at 03:01

22 Answers22

26

For me updating firebase-tools solved the issue

run below command in your cmd prompt

npm install -g firebase-tools

then try firebase init again

Ravi arn
  • 484
  • 4
  • 13
12

First of all, looking into firebase-debug.log in the root of your project (next to firebase.json) might help to define the error. In my case there was "Cannot read property 'deploys' of undefined" error. There's an associated issue on github. Removing extra sites (I didn't actually need them) and leaving only the default one in the Firebase hosting dashboard solved my problem.

LuckyLizard
  • 415
  • 3
  • 13
10

If you still are serving your site on localhost using firebase serve it might cause problems. Shut it down then try the deploy. Worked for me.

Mr. Arbitrary
  • 932
  • 11
  • 25
8

Close the integrated terminal of your IDE by typing exit and hit enter, then re-open it and give the command firebase deploy

If the above option does not work then just use terminal in linux/mac and CMD in windows and navigate to the folder then give firebase deploy command

Riswan
  • 334
  • 3
  • 5
6

In my case, resolve with:

firebase deploy --except functions
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68
  • 5
    While this works for building any other firebase services you are using, it doesn't include the function service... it's kinda like kicking the can down the road if the problem in your environment is firebase functions. – Darrow Hartman Oct 10 '20 at 19:23
  • Very bad. This is not resolving the issue, instead omitting functionality of your app. – codingexplorer Jan 29 '23 at 15:00
4

Below code fixed my issue.

  • Add below code into firebase.json.

     {
        "hosting": {
          "public": "./",
          "ignore": [
            "firebase.json",
            "database-rules.json",
            "storage.rules",
            "functions"
          ],
          "headers": [{
            "source" : "**/*.@(js|html)",
            "headers" : [ {
              "key" : "Cache-Control",
              "value" : "max-age=0"
            } ]
          }]
        }
      }
    
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
3

Make sure that you are logged in by running firebase login in the terminal.

Adam Michalak
  • 155
  • 1
  • 8
George Ogden
  • 596
  • 9
  • 15
2

I was using Firebase functions in the past, I scrapped the idea and created what I wanted in node.js.

So, if you are not using firebase functions remove the following in firebase.json file

      "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  }
2

For me I tried a lot, then I figured out that firebase.json still has functions, I removed it and it worked By the way I was using

firebase deploy --except functions
firebase deploy --only hosting

That didn't help so maybe remove the ones that you don't need

{
  *"functions": {
    "predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint",
  "npm --prefix \"$RESOURCE_DIR\" run build"
 ]
  },*
 "hosting": {
   "public": "build",
   "ignore": [
   "firebase.json",
   "**/.*",
   "**/node_modules/**"
 ]
}
 }
Sam Daived
  • 21
  • 1
1

Yes I've faced this issue.. This is because of my node version I was using Node v.8.0.0 I just downgrade it to Node v.16.0.3 and then my deployment done :)

Rizwan Jamal
  • 1,254
  • 10
  • 13
1

It could be due to npm and node version For mac os, you can update npm using command:

npm install -g npm@latest

and update node directly by going to link https://nodejs.org/en/ and download installer. and run

npm install -g firebase-tools

For removing firebase hosting deployment errors (also if you are updating existing hosted site) you can do process again 1] firebase login 2] firebase init 3] firebase deploy

Make sure your current folder has two things: public folder (which contains all files index.html) And firebase.json file

1

In my case, this error occurred when I had not set the site name in firebase.json.

Example of the firebase.json with site highlighted

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
1

In your firebase.json file, do you have a value set for functions or functions.source? If you do, that may be causing this issue. Remove the functions in angular.json it will work

Firebase document for functions

ragav
  • 29
  • 3
0

I get that error when I haven't run npm install. Try it out. I hope that simple solution helps anyone with the same problem.

Gásten
  • 123
  • 3
  • 8
  • 1
    For me, it worked when I went into the functions directory and ran npm install. See here: https://stackoverflow.com/questions/48602833/eslint-error-while-trying-to-deploy-firebase-functions – Darrow Hartman Oct 10 '20 at 19:22
0

To solve this problem without restart,

  1. You have to make sure you shut down the server, by click on CTRL + C
  2. Then deploy your functions by firebase deploy --only functions
  3. Then run it again firebase --serve
RobC
  • 22,977
  • 20
  • 73
  • 80
lio
  • 419
  • 5
  • 9
0

For me, it is because I run firebase deploy inside functions folder. I need to run it in the parent firebase directory

onmyway133
  • 45,645
  • 31
  • 257
  • 263
0

you should check if you have the folder of nodeJs and the folder of your website in the same local disk first!

I had the same problem, NodeJs was in local disk (D:) and I was trying deploy from local disk (C:), but when I changed the folder of the website to (D:) it worked fine.

0

firebase deploy, firebase serve, firebase ... without any meaningful information in the firebase-debug.log while using Cloud Functions for Firebase?

Check out if you've package.json in your functions folder. It should have all dependencies from your root's package.json, and look somehow like this:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "engines": {
    "node": "12"
  },
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "@angular-builders/custom-webpack": "^11.1.1",
    "@angular/animations": "^11.2.7",
    "@angular/cdk": "^11.2.6",
    ...
  },
  "private": true
}

devDependencies aren't required.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
0

Just check your firebase.json and remove unnecessary dependencies, check mine

{
"hosting": {
"public": "build",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  }
]
}
}
Arihant Jain
  • 817
  • 5
  • 17
0

If it is throwing this error again and again "An unexpected error has occurred. [Reason: Requested entity already exists] in firebase console"

Then instead of doing anything simply restart your system.Then you will get to know it will automatically get registered.

Then click on your ProjectName and click on settings Icon and then you will get the option "See SDK Instructions". Go continue with these steps

-2

FWIW, I had this error while calling firebase deploy from a wrong directory..

Nicolas Degen
  • 1,522
  • 2
  • 15
  • 24
-2

I'm not sure that this is the answer, but I think this happened to me because I was still running npm run dev in another terminal when I did firebase deploy.

Peter Davis
  • 162
  • 1
  • 8