我正在尝试使用部署我的Firebase云功能
firebase deploy --only functions:helloWorld
我的问题是,这个命令有时是成功的,但大多数时候都会失败,出现上面的错误。原因可能是什么,如何解决?
我遇到了一个类似的问题,并尝试了许多推荐的解决方案(清除npm缓存并重新安装依赖项(。两种解决方案对我来说都不可靠。
以下是完整的控制台输出:
=== Deploying to '<my-firebase-project>'...
i deploying functions
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (84.76 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: current functions in project: myFunction1(us-central1), myFunction2(us-central1), myFunction3(us-central1)...
i functions: uploading functions in project: helloWorld(us-central1)
i functions: updating Node.js 10 function helloWorld(us-central1)...
⚠ functions[helloWorld(us-central1)]: Deployment error.
Build failed: npm ERR! Maximum call stack size exceeded
npm ERR! A complete log of this run can be found in:
npm ERR! /builder/home/.npm/_logs/2020-10-15T17_38_33_530Z-debug.log; Error ID: 49341d49
Functions deploy had errors with the following functions:
helloWorld
To try redeploying those functions, run:
firebase deploy --only "functions:helloWorld"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
部分问题是,我不知道在哪里可以找到firebase部署命令输出所说的/builder/home/.npm/_logs/2020-10-15T17_38_33_530Z-debug.log
中的完整日志
下面是我的firebase/functions配置文件:
./functions/index.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) => {
response.send("Hello from Firebase!");
});
./firebase.json
:
{
"functions": {
"predeploy": [
],
"source": "functions",
"runtime": "nodejs10"
},
"emulators": {
"functions": {
"port": 5001
},...
}
...
}
./functions/package.json
:
{
"name": "functions",
"description": "Backend - Firebase Cloud Functions",
"version": "1.0.0",
"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.3.0"
},
"dependencies": {
"config": "^3.3.1",
"core-util-is": "^1.0.2",
"crypto-js": "^4.0.0",
"firebase-admin": "^9.1.1",
"firebase-functions": "^3.11.0",
"myapp_config": "file:./config"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
开发堆栈:
- macOS 10.15+
- 节点版本=v14.3.0
原来问题是我如何在行中构建本地依赖myapp_config
"myapp_config": "file:./config"
。我重新设计了我的应用程序,完全删除了这一行的需求,到目前为止还没有看到部署错误。
/行中指示的config实际上是我用ln-s创建的项目根目录上的config文件夹的符号链接/配置/functions/config最初旨在将项目范围内的配置相关模块交付到我的函数脚本中,而无需手动将这些文件复制到函数中。我想,尽管Firebase函数支持本地Node.js依赖项,但CLI/npm不知何故被符号链接弄糊涂了,或者不能很好地使用符号链接(我猜它看到了./config
和它的符号链接./functions/config
,并在它们之间进入了某种无限循环(
另一个问题揭示了我的代码结构,以及我最初试图解决的问题。