firebase deploy command for Node.js application results in Error: `runtime` field is required but was not found in firebase.json

firebase deploy command for Node.js application results in Error: `runtime` field is required but was not found in firebase.json

我正在尝试在 firebase 中部署我的 Node.js 应用程序,但是当我 运行 命令时它导致错误 Error: 运行time field is required but was not found in firebase.json.

我尝试了 运行 命令 firebase serve --only functions,hosting 并且在本地一切正常,所以我想部署并提供 link 给我的同事进行用户测试,但我不能使用 firebase deploy 命令来完成。

我尝试将命令添加到我的 firebase.json 文件中,但仍然没有成功。这是我的原始 firebase.json 文件:

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]
  }
}

报错后改成这样:

{
  "hosting": {
    "public": "public",
    "runtime": "nodejs10",
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]
  }
}

仍然出现错误,我有点困惑我到底需要在什么地方添加命令 "runtime": "nodejs10",。我试着寻找但找不到任何关于类似问题的相关文章,任何人都可以帮助我。

要设置 运行 时间,请在 package.json 文件的 engines 字段中设置版本,该文件是在初始化期间在您的 functions/ 目录中创建的。例如,要仅使用版本 10,请在 package.json:

中编辑此行

"engines":{"node":"10"}

引擎字段是必需的;它必须指定受支持的 Node.js 版本之一,以便您部署和 运行 功能。目前,firebase init 函数将此字段设置为节点 10

错误消息说将其添加到“functions”部分。您将其添加到“托管”部分,这将不起作用。运行时选择是针对 Cloud Functions 而不是 Firebase 托管。它们是具有不同配置的不同产品。

该消息关于要添加的内容也不完全准确。

将运行时添加到函数部分,如 documentation:

中所述
{
  "functions": {
    "engines": {"node": "10"}
  }
}