Firebase 函数部署失败,并出现"缺少"依赖项错误



我在尝试部署Firebase功能时遇到错误。尽管删除了node_modulespackage-lock.json,运行了npm install,并执行了firebase deploy --only functions多次,构建过程仍然失败,出现以下错误:

Build failed: ...regex-range@5.0.1 from lock file
npm ERR! Missing: brace-expansion@1.1.11 from lock file
npm ERR! Missing: balanced-match@1.0.2 from lock file
npm ERR! Missing: concat-map@0.0.1 from lock file
npm ERR! Missing: mimic-fn@2.1.0 from lock file
npm ERR! Missing: p-limit@2.3.0 from lock file
npm ERR! Missing: error-ex@1.3.2 from lock file
npm ERR! Missing: json-parse-even-better-errors@2.3.1 from lock file
npm ERR! Missing: lines-and-columns@1.2.4 from lock file
npm ERR! Missing: is-arrayish@0.2.1 from lock file
npm ERR! Missing: ansi-styles@5.2.0 from lock file
npm ERR! Missing: react-is@18.2.0 from lock file
npm ERR! Missing: kleur@3.0.3 from lock file
npm ERR! Missing: sisteransi@1.0.5 from lock file
npm ERR! Missing: is-core-module@2.11.0 from lock file
npm ERR! Missing: path-parse@1.0.7 from lock file
npm ERR! Missing: supports-preserve-symlinks-flag@1.0.0 from lock file
npm ERR! Missing: shebang-regex@3.0.0 from lock file
npm ERR! Missing: buffer-from@1.1.2 from lock file
npm ERR! Missing: escape-string-regexp@2.0.0 from lock file
npm ERR! Missing: char-regex@1.0.2 from lock file
npm ERR! Missing: has-flag@4.0.0 from lock file
npm ERR! Missing: is-number@7.0.0 from lock file
npm ERR! Missing: picocolors@1.0.0 from lock file
npm ERR! Missing: convert-source-map@1.9.0 from lock file
npm ERR! Missing: makeerror@1.0.12 from lock file
npm ERR! Missing: tmpl@1.0.5 from lock file
npm ERR! Missing: isexe@2.0.0 from lock file
npm ERR! Missing: ms@2.1.2 from lock file
npm ERR! Missing: yallist@3.1.1 from lock file
npm ERR! Missing: ansi-styles@3.2.1 from lock file
npm ERR! Missing: escape-string-regexp@1.0.5 from lock file
npm ERR! Missing: supports-color@5.5.0 from lock file
npm ERR! Missing: color-convert@1.9.3 from lock file
npm ERR! Missing: color-name@1.1.3 from lock file
npm ERR! Missing: has-flag@3.0.0 from lock file
npm ERR! Missing: ms@2.1.2 from lock file
npm ERR! Missing: ms@2.1.2 from lock file
npm ERR! Missing: cliui@8.0.1 from lock file
npm ERR! Missing: yargs-parser@21.1.1 from lock file
npm ERR! Missing: p-try@2.2.0 from lock file
npm ERR!
npm ERR! Clean install a project
npm ERR!
npm ERR! Usage:
npm ERR! npm ci
npm ERR!
npm ERR! Options:
npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]      
npm ERR! [-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
npm ERR! [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
npm ERR!
npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
npm ERR!
npm ERR! Run "npm help ci" for more info
npm ERR! A complete log of this run can be found in:
npm ERR!     /www-data-home/.npm/_logs/2023-04-09T09_55_08_623Z-debug-0.log; Error ID: beaf8772      
Functions deploy had errors with the following functions:
update(asia-east2)
i  functions: cleaning up build files...
Error: There was an error deploying 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"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.0.0",
"firebase-functions": "^4.0.0",
"stripe": "^8.0.0"
},
"devDependencies": {
"firebase-functions-test": "^3.0.0"
},
"private": true,
"engines": {
"node": "16"
}
}

firebase.json

{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}

我没有.gcloudignore但是.gitignore:

node_modules/

我手动npm安装了它们中的每一个,但每当我执行firebase deploy --only functions时,它总是要求更多。现在我的package-lock.json有数百个包。

我正在测试的代码:

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

我所采取的步骤:

  1. npm install -g firebase-tools

  2. firebase login

  3. firebase init functions-使用现有项目…

  4. cd functions

  5. npm i stripe

  6. editindex.js

  7. firebase deploy --only functions

在Firebase仪表板上,此功能由红色三角形表示,并显示消息"功能部署失败"。请再试一次。

我也尝试在我的package.json文件中更新受影响的包,但错误仍然存在。

我不确定是什么导致了这个问题,我将非常感谢任何关于如何解决它的指导或建议。谢谢你的帮助。

我检查了firebase-debug.log,它包含Could not find functions.yaml. Must use http discovery:

...
[debug] [2023-04-12T00:48:22.311Z] Building nodejs source
[debug] [2023-04-12T00:48:22.312Z] Could not find functions.yaml. Must use http discovery
[debug] [2023-04-12T00:48:22.319Z] Found firebase-functions binary at 'C:UsersmunicDesktopprogrammingpenvietestfuncfunctionsnode_modules.binfirebase-functions'
[debug] [2023-04-12T00:48:22.460Z] Serving at port 8008
[debug] [2023-04-12T00:48:22.666Z] Got response from /__/functions.yaml {"endpoints":{"helloWorld":{"platform":"gcfv1","availableMemoryMb":null,"timeoutSeconds":null,"minInstances":null,"maxInstances":null,"ingressSettings":null,"serviceAccountEmail":null,"vpc":null,"httpsTrigger":{},"entryPoint":"helloWorld"}},"specVersion":"v1alpha1","requiredAPIs":[]}
[debug] [2023-04-12T00:48:22.672Z] shutdown requested via /__/quitquitquit
[info] i  functions: preparing functions directory for uploading... 
[info] i  functions: packaged C:UsersmunicDesktopprogrammingpenvietestfuncfunctions (63.59 KB) for uploading 
...

在阅读了类似的问题后,我看到他们建议将firebase-tools降级为10.0.0,10.8.0,11.17.0,11.18.0,11.20.011.22.0。大多数情况下,他们更愿意将其降级为11.17.0

npm i -g firebase-tools@11.17.0

在重现您的问题后,我采取了以下步骤进行调试。

在开始调试过程之前,您应该检查以下几件事情:

  1. 检查您的Firebase项目首先升级到Blaze计划。然后,将升级后的项目与您的代码连接起来。
  2. 确保您的节点环境是版本16。我正在使用16.13.1,它可以工作。您必须使用版本16,因为在您的包中。Json文件,您已经提到节点版本为16。你可以使用nvm [Node Version Manager]。我强烈建议您使用与我相同的版本。
  3. 使用更新后的节点版本再次在项目中运行npm install。它将成功安装所有依赖项。
  4. 删除旧的Firebase云功能并尝试重新部署

有同样的错误,在构建服务器上由npm ci触发:

npm ci只能在你安装包的时候安装。Json和包锁。Json或npm-shrinkwrap。Json是同步的。请使用npm install更新您的锁文件,然后再继续

这是由于在npm上启用了global legacy-peer-deps。一旦我删除它并运行npm install,错误就消失了,函数也部署了。

感谢Jordy的回答,我可以在降级firebase-tools后进行部署:

npm i -g firebase-tools@11.17.0

然而,我想通过说你必须有节点16来完成答案

firebase-tools的降级在我的节点18上不起作用。

最新更新