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

部署Firebase函数遇Cannot find module 'firebase-functions'错误求助

Fixing "Cannot find module 'firebase-functions'" Error When Deploying Firebase Functions

Let’s work through this issue step by step—since you’ve already tried the basic npm install and still hit this error, we need to dig into a few less obvious fixes:

1. Upgrade Your Node.js Version

Your current Node.js version (v7.0.0) is extremely outdated. Firebase Functions requires at least Node.js v14 (LTS versions like v18 or v20 are recommended now). Older Node versions can cause npm to fail installing modern dependencies correctly, and some packages (including firebase-functions) might not even support such old versions.

  • Install a recent LTS version via nvm (the easiest way to manage Node versions) or the official Node.js website.
  • After upgrading, restart your terminal to ensure the new Node/npm version is active.

2. Do a Clean Dependency Install

Cached files or incomplete installs can leave dependencies in a broken state. Let’s reset everything:

  • Navigate to your functions directory:
    cd /Users/user/Documents/Projects/firebase/hnpwa-firebase/functions
    
  • Delete the existing node_modules folder and lock file:
    rm -rf node_modules package-lock.json
    
    (For Windows, use rmdir /s node_modules and del package-lock.json)
  • Clear npm’s cache to eliminate any corrupted cached packages:
    npm cache clean --force
    
  • Reinstall dependencies from scratch:
    npm install
    

3. Check firebase-functions is in Dependencies

Double-check your package.json in the functions directory to make sure firebase-functions is listed under dependencies (not devDependencies). Firebase only installs packages in dependencies during deployment.

You should see something like this:

"dependencies": {
  "firebase-functions": "^4.0.0",
  // other dependencies...
}

If it’s in devDependencies, move it to dependencies and re-run npm install.

4. Verify Firebase Deployment Configuration

Your deployment targets the dist/server directory—make sure your firebase.json is set up correctly to point to the right source and run the build script properly. It should look similar to this:

{
  "functions": {
    "source": "functions",
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
}

This ensures the TypeScript code is compiled to dist before deployment, and Firebase can locate the compiled files with the correct dependencies.

5. Upgrade Firebase CLI

Outdated Firebase CLI versions can cause compatibility issues with newer firebase-functions versions. Upgrade it globally:

npm install -g firebase-tools

After trying these steps, attempt to deploy again with firebase deploy --only functions. This should resolve the module not found error.

内容的提问来源于stack exchange,提问作者Pyae Phyoe Shein

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:24:24