Firebase 功能无法部署

Ren*_*ens 9 node.js firebase google-cloud-functions

我正在尝试创建 Firebase 函数,但遇到部署错误,即使在部署默认helloworld函数时也是如此。

firebase-debug.log 文件提到了这一点: Could not find image for function projects/picci-e030e/locations/us-central1/functions/helloWorld.

我一直在尝试调试,但到目前为止还无法解决它......

firebase-debug.log

[info] Functions deploy had errors with the following functions:
    helloWorld(us-central1)
[debug] [2021-11-18T21:54:08.946Z] Missing URI for HTTPS function in printTriggerUrls. This shouldn't happen
[info] i  functions: cleaning up build files... 
[debug] [2021-11-18T21:54:08.948Z] >>> [apiv2][query] GET https://us.gcr.io/v2/picci-e030e/gcf/us-central1/tags/list [none]
[debug] [2021-11-18T21:54:09.407Z] <<< [apiv2][status] GET https://us.gcr.io/v2/picci-e030e/gcf/us-central1/tags/list 200
[debug] [2021-11-18T21:54:09.407Z] <<< [apiv2][body] GET https://us.gcr.io/v2/picci-e030e/gcf/us-central1/tags/list {"child":[],"manifest":{},"name":"picci-e030e/gcf/us-central1","tags":[]}
[debug] [2021-11-18T21:54:09.407Z] Could not find image for function projects/picci-e030e/locations/us-central1/functions/helloWorld
[debug] [2021-11-18T21:54:09.481Z] Error: Failed to create function helloWorld in region us-central1
    at /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:38:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Fabricator.createV1Function (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:161:32)
    at async Fabricator.createEndpoint (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:116:13)
    at async handle (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:75:17)
[error] 
[error] Error: There was an error deploying functions
Run Code Online (Sandbox Code Playgroud)

索引.js:

const functions = require("firebase-functions");

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

// const getBlurhash = require("./get_blurhash");
// exports.getBlurhash = getBlurhash.generateHash;
Run Code Online (Sandbox Code Playgroud)

包.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1",
    "blurhash": "^1.1.4"
  },
  "devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
Run Code Online (Sandbox Code Playgroud)

我的节点版本: v14.16.0

感谢你的帮助。

JM *_*lio 14

找不到函数项目/picci-e030e/locations/us-central1/functions/helloWorld 的图像。

Firebase Function 部署失败,因为它找不到基于您的函数应用构建的映像。您的应用程序中的构建可能存在问题,可能是您的依赖项或文件。

我复制了你的问题,收到了同样的错误并解决了。package.json文件和都有问题package-lock.json。如果您只是添加(而不安装)您的依赖项,package.json 则应删除或删除package-lock.json在函数目录中找到的依赖项,然后再使用部署命令再次部署它:

firebase deploy --only functions
Run Code Online (Sandbox Code Playgroud)

或者您可以只安装依赖项以确保它将添加到您的package.json文件中package-lock.json,然后再次部署。例如:

npm install --save blurhash
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!我将依赖项安装在主项目文件夹中,而不是函数文件夹中。我注意到package.json不包含blurhash依赖项并手动添加它。Obv 那没有成功。我从头开始重新创建了该项目,并将依赖项安装在函数文件夹中,并且部署成功。 (2认同)