“An unexpected error has occurred” after firebase deploy

余生长醉 提交于 2019-12-01 16:42:39

问题


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>

回答1:


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




回答2:


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




回答3:


Copy this and paste inside of 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"
        } ]
      }]
    }
  }



回答4:


In my case, resolve with:

firebase deploy --except functions



回答5:


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




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/42475477/an-unexpected-error-has-occurred-after-firebase-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!