在firebase.json中未指定site属性时,firebase部署错误

时间:2020-05-03 14:41:58

标签: firebase deployment firebase-hosting

我正在使用Firebase托管,当我尝试部署项目时,出现以下错误:

enter image description here

firebase日志显示以下内容:

[调试] [2020-05-03T14:31:51.377Z] TypeError:无法读取未定义的属性“ deploys” 在C:\ Users \ albert.valeta \ AppData \ Roaming \ npm \ node_modules \ firebase-tools \ lib \ deploy \ index.js:84:36 在process._tickCallback(internal / process / next_tick.js:68:7)

我正在使用的命令是:

firebase部署-仅托管:last-call-manager-pre

firebase.json是:

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

奇怪的是,当我将 site 属性添加到firebase.json时,不会抛出任何错误并完成了部署。该firebase.json看起来像:

{
  "hosting": {
    "site": "last-call-manager-pre",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我关心该错误,因为我有2个不同的环境,并且我不想每次为每个目标环境进行部署时都修改firebase.json文件。此外,我不清楚该网站属性的确切含义,也没有找到太多有关此信息。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

假设我有一个项目,其中有 2 个环境(test + prod),它们位于 2 个不同的 Firebase 项目中。每个 firebase 项目都包含多个应用,因此我还需要在每个项目中指定要部署到哪个应用。

Firebase project name for test is "firebase-app-test"
Firebase project name for prod is "firebase-app-prod"
App name in the test Firebase project is "app-test"
App name in the prod Firebase project is "app-prod"

firebase.json 看起来像这样:

{
  "hosting": [
    {
    "target": "test",
    "public": "dist",
    ... rest of settings for test project
    },
   { 
    "target": "production",
    "public": "dist",
    ... rest of settings for prod project
   }
 ]
}

.firebaserc 然后看起来像:

{
  "projects": {
    "default": "firebase-project-test",
    "test": "firebase-project-test",
    "production": "firebase-project-prod"
  },
  "targets": {
    "firebase-project-prod": {
      "hosting": {
        "production": [
          "app-prod"  
        ]
      }
    },
    "firebase-project-test": {
      "hosting": {
        "test": [
          "app-test"
        ]
      }
    }  
  }
}

将测试应用部署到 firebase-project-test:

firebase deploy --only hosting:test --project test

将 prod 应用部署到 firebase-project-prod

firebase deploy --only hosting:production --project production
相关问题