【问题标题】:Firebase deploy issue: Build failed: npm ERR! Maximum call stack size exceededFirebase 部署问题:构建失败:npm ERR!超出最大调用堆栈大小
【发布时间】:2020-10-21 02:52:37
【问题描述】:

我正在尝试通过以下方式部署我的 Firebase Cloud Function:

firebase deploy --only functions:helloWorld

我的问题是该命令有时会成功,但大多数时候它会因上述错误而失败。可能是什么原因,如何解决?

我遇到了similar question 并尝试了许多推荐的解决方案(清除 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 deploy 命令输出中提到的完整日志在 /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

【问题讨论】:

  • 你是说它给你的日志文件是空的或丢失的还是什么?只需cat 文件即可查看其中的内容。问题可能出在您的代码上,因此您应该编辑问题以显示重现该问题的 complete minimal code,以便任何人都可以使用您提供的说明重现此问题。
  • @DougStevenson 我不知道日志文件在哪里。当我这样做时,ls /builder/home 我得到:ls: /builder/home: No such file or directory。它应该在 macOS 机器上的什么位置?
  • @DougStevenson 我编辑了这个问题以提供一个最小的例子 - 上面的 index.js 文件是否足够或需要其他任何东西?
  • 我在这里没有看到问题,但是该日志文件的内容应该有您需要的内容。如果 CLI 没有为您提供关于部署期间出现问题的完整或可操作的错误,您应该直接联系 Firebase 支持。 support.google.com/firebase/contact/support

标签: firebase npm deployment google-cloud-functions


【解决方案1】:

原来问题是我如何在行中构建本地依赖项myapp_config "myapp_config": "file:./config"。我重新设计了我的应用程序以完全删除 [the need for] 这条线,到目前为止还没有再次看到部署错误。

在该行中指示的 ./config 实际上是我创建的项目根目录上的 config 文件夹的符号链接:ln -s ./config ./functions/config 最初打算交付项目范围的配置相关模块到我的函数脚本中,而无需手动将这些文件复制到函数中。我想和Firebase Functions supports local Node.js dependencies 一样,CLI/npm 不知何故会被符号链接弄糊涂或不能很好地工作(我猜它看到./config 及其符号链接./functions/config 并进入它们之间的无限循环)

This other question 更清楚地说明了我的代码结构以及我最初试图解决的问题。

【讨论】:

    猜你喜欢
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2021-02-12
    • 2019-03-01
    • 2018-06-03
    • 2019-07-19
    • 2017-06-12
    相关资源
    最近更新 更多