You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Functions部署失败:npm ci依赖同步错误求助

Firebase Functions部署失败:npm ci依赖同步错误

问题详情

执行firebase deploy --only functions部署Firebase Functions时持续构建失败,提示npm ci要求package.json与package-lock.json同步,lock文件缺失@firebase/app-compat@0.2.3等多个包。本地用Firebase模拟器测试正常,已尝试npm install和npm ci但问题未解决。

报错日志

Build failed: npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Missing: @firebase/app-compat@0.2.3 from lock file
npm ERR! Missing: @firebase/app@0.9.3 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: idb@7.0.1 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-02-18T13_26_52_861Z-debug-0.log; Error ID: beaf8772
Build failed: npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Missing: @firebase/app-compat@0.2.3 from lock file
npm ERR! Missing: @firebase/app@0.9.3 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: idb@7.0.1 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-02-18T13_27_30_745Z-debug-0.log; Error ID: beaf8772
Build failed: npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Missing: @firebase/app-compat@0.2.3 from lock file
npm ERR! Missing: @firebase/app@0.9.3 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: idb@7.0.1 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-02-18T13_27_26_236Z-debug-0.log; Error ID: beaf8772
Build failed: npm ERR! code EUSAGE
npm ERR! 
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! Missing: @firebase/app-compat@0.2.3 from lock file
npm ERR! Missing: @firebase/app@0.9.3 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: @firebase/component@0.6.3 from lock file
npm ERR! Missing: @firebase/logger@0.4.0 from lock file
npm ERR! Missing: @firebase/util@1.9.2 from lock file
npm ERR! Missing: idb@7.0.1 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-02-18T13_27_31_642Z-debug-0.log; Error ID: beaf8772

Functions deploy had errors with the following functions:
        randomNumberCall(europe-west3)
        randomNumberRequest(europe-west3)
        stripeCheckout(europe-west3)
        stripeCheckoutWithoutDbQueries(europe-west3)
i  functions: cleaning up build files...
Error: There was an error deploying functions:
- Error Failed to create function stripeCheckout in region europe-west3
- Error Failed to create function stripeCheckoutWithoutDbQueries in region europe-west3
- Error Failed to create function randomNumberCall in region europe-west3
- Error Failed to create function randomNumberRequest in region europe-west3

相关代码(index.js)

const stripe = require("stripe")(
    "sk_test_XXXXXXXX"
);

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

exports.stripeCheckout = functions
    .region("europe-west3")
    .https.onCall(async (data, context) => {
        console.log(data);

        const session = await stripe.checkout.sessions.create({
            payment_method_types: ["card"],
            line_items: data.items.map((item) => ({
                quantity: 1,
                price_data: {
                    currency: "eur",
                    unit_amount: item.price * 100,
                    product_data: {
                        name: item.summary,
                        // description: "description!"
                        images: [item.image]
                    }
                }
            })),

            mode: "payment",
            success_url: "http://localhost:4205/home?action=success",
            cancel_url: "http://localhost:4205/home?action=cancel"
        });

        return session.id;
    });

解决方案

1. 彻底重置依赖锁文件

  • 删除本地的package-lock.json和node_modules文件夹:
    rm -rf package-lock.json node_modules
    
  • 重新安装依赖,生成新的锁文件:
    npm install
    
  • 再次尝试部署:
    firebase deploy --only functions
    

2. 检查Firebase CLI版本

旧版本CLI可能存在依赖处理bug,更新到最新版:

npm install -g firebase-tools

3. 确认依赖版本兼容性

检查package.json中firebase-functions和firebase-admin的版本是否匹配,建议使用官方推荐的兼容版本组合,避免版本冲突导致锁文件异常。

4. 禁用npm ci强制使用npm install(临时方案)

在firebase.json中添加配置,让部署时使用npm install而非npm ci:

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" install"
    ]
  }
}

内容的提问来源于stack exchange,提问作者linka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 09:02:51