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

已安装firebase-functions仍提示找不到模块,求助排查方案

Fixing the "cannot find module 'firebase-functions'" Lint Error

Hey there, that error popping up even after you’ve run npm i firebase-functions and restarted VS Code is definitely frustrating—and you’re spot-on to suspect your tsconfig or webpack config as potential causes. Let’s break down the most likely fixes step by step:

1. Double-check your tsconfig.json module resolution settings

TypeScript’s module resolution strategy is often the culprit here. Open up your tsconfig.json and verify these key points:

  • Make sure moduleResolution in compilerOptions is set to node—this is the standard resolution method for Node.js modules like firebase-functions:
    "compilerOptions": {
      "moduleResolution": "node",
      // ... other configs
    }
    
  • If you’ve set a baseUrl or custom paths for module aliasing, ensure you haven’t accidentally overridden the path for firebase-related modules. You can temporarily comment out the paths section to test if that resolves the error.
  • Confirm your include array covers the directory where you’re importing firebase-functions. For example, if your cloud function code lives in a functions/ folder alongside your Angular app:
    "include": [
      "src/**/*",
      "functions/**/*"
    ]
    

2. Verify your webpack configuration

If your project uses webpack, its resolve rules might be blocking the module from being found:

  • Check webpack.config.js to ensure resolve.extensions includes .js and .ts—firebase-functions ships as a JavaScript module, so TypeScript needs to be able to resolve it:
    resolve: {
      extensions: ['.ts', '.js', '.json']
    }
    
  • Make sure you haven’t set an incorrect alias for firebase-functions in resolve.alias—this would redirect the module lookup to a non-existent path.

3. Confirm the packages are actually installed properly

Even though you ran npm i, it’s worth double-checking:

  • Navigate to your project’s node_modules folder and confirm both firebase-functions and firebase-admin directories exist, with their full set of files (like index.js and their own package.json).
  • If the folders are missing, delete node_modules and package-lock.json (or yarn.lock if you use Yarn), then re-run npm install and watch for any installation errors that might have been missed earlier.

4. Check your lint tool’s configuration

If you’re using ESLint or TSLint, their settings might be independent of TypeScript’s:

  • For ESLint, open .eslintrc.json and ensure you’ve enabled the Node.js environment (this helps ESLint recognize Node modules):
    "env": {
      "node": true
    }
    
    Also, check the settings.node.paths option to make sure it includes your node_modules directory if you’ve customized it.
  • For TSLint, verify tslint.json doesn’t have rules that incorrectly flag module imports or override module resolution paths.

5. Angular-specific note

Since your project is Angular 5, keep in mind: firebase-functions is primarily designed for backend cloud function code, not frontend Angular apps. If you’re trying to call cloud functions from your Angular frontend, you should install the regular firebase package instead, and access functions via firebase.functions().

If you do need to use firebase-functions in your Angular project (e.g., for local cloud function development), just make sure your tsconfig is correctly set up to recognize Node.js modules as outlined above.

内容的提问来源于stack exchange,提问作者İbrahim Dolapci

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:01:07