12
votes

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>
19
I'd recommend reaching out to Firebase support and include the output of firebase deploy --debug in your message. - Michael Bleigh
follow this tutorial step by step or watch youtube video on this blog. you will understand everything. codingaffairs.blogspot.com/2017/06/… - Developine
npm install -g npm@latest - Ronnie Royston

19 Answers

22
votes

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

7
votes

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.

5
votes

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

5
votes

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.

4
votes

In my case, resolve with:

firebase deploy --except functions
4
votes

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

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

2
votes

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
votes

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/**"
 ]
}
 }
1
votes

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 :)

1
votes

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
votes

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

0
votes

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.

0
votes

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
0
votes

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

0
votes

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

0
votes

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
votes

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.

0
votes

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

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