部署函数时出错。无法更新区域 us-central1 中的函数应用
There was an error deploying functions. Failed to update function app in region us-central1
这是我第一次尝试部署 firebase 函数。我写了一个 API,我想创建一个 firebase 函数并使用它。
在我的项目中,一切都在 localhost 上工作,甚至在我做的时候工作 firebase serve --only functions, hosting
。
因为我只使用 hosting
和 functions
我没有做 firebase 配置的 initializeApp(firebaseConfig)
事情(不确定是否需要)。
我的functions/index.js
是:
//functions/index.js
const functions = require("firebase-functions");
const express = require('express');
const bodyParser = require('body-parser');
var connection = require('../utils/dbconfig'); //outside functions folder
const app = express();
app.use(bodyParser.json());
// API START HERE
app.get('/getEmployees', (req, res) => {
// Here I connect to db which has it's configurations in dbConfig.js
res.send(result);
});
// API END HERE
exports.app = functions.https.onRequest(app);
我已经从主项目文件夹(外部函数)中的 index.js
和 function
文件夹中手动粘贴了这段代码,我还有另一个 index.js
,和 package.json
文件,它们是 auto-generated 并且我在 functions
文件夹外部的 package.js
中添加了依赖项。然后在 functions
文件夹中,我做了 npm install
.
这是我的 functions/package.json
文件:
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"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": "16"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"body-parser": "~1.0.1",
"express": "~4.0.0",
"tedious": "^14.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"nodemon": "^2.0.15"
},
"private": true
}
那么唯一的 firebase.json
文件有这些设置:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
}
当我执行 firebase deploy
(部署功能和托管)或 firebase deploy --only functions
时,我收到一个错误,我从中获取了最后 10 行:
[debug] [2022-03-08T02:48:07.963Z] <<< [apiv2][body] DELETE https://us.gcr.io/v2/ventes-4f9b6/gcf/us-central1/053feedd-aed4-4c8d-93c4-591b134374b6/cache/manifests/sha256:7b2b71f239340ebec209e230e76e303b6fd7293c8f23ee3292f23d8cf4571319 {"errors":[]}
[debug] [2022-03-08T02:48:08.022Z] Error: Failed to update function app 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:95:5)
at async Fabricator.updateV1Function (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:255:32)
at async Fabricator.updateEndpoint (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:136: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
我尝试过具有相似标题的不同解决方案,但目前没有任何效果。我也尝试在 functions
文件夹中再次安装软件包,但对我来说没有任何问题。
函数文件夹外不能有文件。只有 functions 文件夹中的内容才会被部署。将它移到您的函数文件夹中。
var connection = require('../utils/dbconfig'); //outside functions folder
此外,functions.https.onRequest
处理 parsing the body of incoming requests,因此使用任何正文解析器都可能导致错误,您应该将其删除。
这是我第一次尝试部署 firebase 函数。我写了一个 API,我想创建一个 firebase 函数并使用它。
在我的项目中,一切都在 localhost 上工作,甚至在我做的时候工作 firebase serve --only functions, hosting
。
因为我只使用 hosting
和 functions
我没有做 firebase 配置的 initializeApp(firebaseConfig)
事情(不确定是否需要)。
我的functions/index.js
是:
//functions/index.js
const functions = require("firebase-functions");
const express = require('express');
const bodyParser = require('body-parser');
var connection = require('../utils/dbconfig'); //outside functions folder
const app = express();
app.use(bodyParser.json());
// API START HERE
app.get('/getEmployees', (req, res) => {
// Here I connect to db which has it's configurations in dbConfig.js
res.send(result);
});
// API END HERE
exports.app = functions.https.onRequest(app);
我已经从主项目文件夹(外部函数)中的 index.js
和 function
文件夹中手动粘贴了这段代码,我还有另一个 index.js
,和 package.json
文件,它们是 auto-generated 并且我在 functions
文件夹外部的 package.js
中添加了依赖项。然后在 functions
文件夹中,我做了 npm install
.
这是我的 functions/package.json
文件:
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"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": "16"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"body-parser": "~1.0.1",
"express": "~4.0.0",
"tedious": "^14.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"nodemon": "^2.0.15"
},
"private": true
}
那么唯一的 firebase.json
文件有这些设置:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
}
当我执行 firebase deploy
(部署功能和托管)或 firebase deploy --only functions
时,我收到一个错误,我从中获取了最后 10 行:
[debug] [2022-03-08T02:48:07.963Z] <<< [apiv2][body] DELETE https://us.gcr.io/v2/ventes-4f9b6/gcf/us-central1/053feedd-aed4-4c8d-93c4-591b134374b6/cache/manifests/sha256:7b2b71f239340ebec209e230e76e303b6fd7293c8f23ee3292f23d8cf4571319 {"errors":[]}
[debug] [2022-03-08T02:48:08.022Z] Error: Failed to update function app 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:95:5)
at async Fabricator.updateV1Function (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:255:32)
at async Fabricator.updateEndpoint (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:136: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
我尝试过具有相似标题的不同解决方案,但目前没有任何效果。我也尝试在 functions
文件夹中再次安装软件包,但对我来说没有任何问题。
函数文件夹外不能有文件。只有 functions 文件夹中的内容才会被部署。将它移到您的函数文件夹中。
var connection = require('../utils/dbconfig'); //outside functions folder
此外,functions.https.onRequest
处理 parsing the body of incoming requests,因此使用任何正文解析器都可能导致错误,您应该将其删除。