更新Node.js 16 Firebase Cloud Function时出错(Angular 14/Universal)
解决Angular SSR部署到Firebase Functions时的npm ci错误
问题场景
尝试用Angular 14 + Angular Universal + Firebase Cloud Functions实现服务端渲染(SSR),执行部署命令firebase deploy --only hosting, functions时触发以下错误:
i functions: updating Node.js 16 function ngssr(us-central1)... Build failed: npm ERR! The `npm ci` command can only install with an existing package-lock.json or npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or npm ERR! later to generate a package-lock.json file, then try again. npm ERR! A complete log of this run can be found in: npm ERR! /www-data-home/.npm/_logs/2022-07-30T14_01_32_156Z-debug-0.log; Error ID: beaf8772 Functions deploy had errors with the following functions: ngssr(us-central1) i functions: cleaning up build files...
解决步骤
- 检查并生成package-lock.json:分别查看项目根目录和
functions子目录,若缺少package-lock.json,在对应目录执行npm install生成该文件。 - 更新lockfile版本:如果已有
package-lock.json但版本低于1,执行npm install(确保本地npm版本为5及以上),会自动将lockfile版本更新至符合要求的格式。 - 验证Functions目录配置:进入
functions目录,确认package.json中没有禁用lockfile生成的配置;同时本地执行npm -v验证npm版本,Node.js 16配套的npm版本默认满足5+要求。 - 重新执行部署:完成上述操作后,再次运行
firebase deploy --only hosting, functions。
额外提示
如果functions目录是Angular Universal自动生成的,需单独进入该目录执行npm install,确保子目录下的lockfile正确生成——Firebase部署函数时会独立处理functions目录的依赖安装流程。
内容的提问来源于stack exchange,提问作者chadoulis
相关产品推荐
相关产品推荐

