简体   繁体   English

Firebase 部署错误 - 找不到模块“firebase”

[英]Firebase deploy error - Cannot find module 'firebase'

I'm trying to deploy Google Cloud function triggers that trigger from db events, but when I run firebase deploy The functions aren't deployed properly and I get an error saying Error: Cannot find module firebase我正在尝试部署从 db 事件触发的 Google Cloud 函数触发器,但是当我运行firebase deploy函数未正确部署并且我收到一条错误消息Error: Cannot find module firebase

When I was first creating the project I could deploy functions without any issues.当我第一次创建项目时,我可以毫无问题地部署功能。 It's been a few days since I last deployed anything, but now I'm getting this issue on all my functions (not just my trigger functions)自从我上次部署任何东西以来已经有几天了,但现在我的所有功能都遇到了这个问题(不仅仅是我的触发功能)

My function:我的功能:

exports.deleteNotificationOnUnlike = functions
    .region("us-central1")
    .firestore.document("likes/{id}")
    .onDelete((snapshot) => {
        return db
            .doc(`/notifications/${snapshot.id}`)
            .delete()
            .catch((err) => console.error(err));
    });

Package.json包.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "busboy": "^0.3.1",
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

Expecting the functions to deploy successfully but getting this error:期望功能成功部署但收到此错误:

Error messages from firebase:来自 firebase 的错误消息:

Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/srv/handlers/users.js:5:18)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"INVALID_ARGUMENT"},"authenticationInfo":{"principalEmail":"*********"},"requestMetadata":{"requestAttributes":{},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.CreateFunction","resourceName":"projects/*******/locations/us-central1/functions/createNotificationOnComment"}

I've seen some posts where people were missing some modules and needed to run an npm i XXX inside the functions folder, but I haven't seen any instances where it was saying that the firebase module couldn't be found, and I'm not sure what changes from my last successful deployment, or what module I might be missing.我看过一些帖子,人们缺少一些模块,需要在函数文件夹中运行npm i XXX ,但我没有看到任何实例说找不到 firebase 模块,而且我我不确定我上次成功部署有什么变化,或者我可能缺少什么模块。

Figured out the solution.想出了解决办法。 I hadn't installed the firebase module in the functions folder but had included it in the parent folder of functions .我没有在 functions 文件夹中安装 firebase 模块,而是将其包含在functions的父文件夹中。 I went into functions and ran npm install --save firebase and the deploy was successful.我进入功能并运行npm install --save firebase并且部署成功。

Make sure you installed the package from the functions directory, Not the project directory.确保从函数目录安装包,而不是项目目录。 I got this error many times when I accidentally installed packages while in the project directory, It worked fine locally, but created such errors during deployment.当我在项目目录中意外安装软件包时,我多次收到此错误,它在本地运行良好,但在部署期间创建了此类错误。 So, goto functions and install from there因此,转到功能并从那里安装

cd functions
npm install [your package]

Then it usually works fine然后它通常工作正常

Try updating firebase npm package, mine was solved using npm install -D firebase .尝试更新 firebase npm 包,我的解决方法是使用npm install -D firebase

-Stay Safe! -注意安全!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase部署后-错误:找不到模块 - After Firebase deploy - Error: cannot find module FIrebase 部署错误:找不到模块“firebase-admin” - FIrebase deploy error: Cannot find module 'firebase-admin' Angular Firebase函数部署错误:找不到模块“ firebase / app” - Angular Firebase Function Deploy Error: Cannot find module 'firebase/app' Firebase功能部署错误找不到模块firebase-admin - Firebase function deploy error cannot find module firebase-admin Firebase找不到“模块” <Firebase> “ - Firebase cannot find 'module <Firebase>' 无法部署Firebase云功能[无法找到模块&#39;protobufjs / minimal&#39;] - Cannot deploy Firebase Cloud Functions [Cannot find module 'protobufjs/minimal'] 错误:找不到模块“ @ firebase / polyfill” - Error: Cannot find module “@firebase/polyfill” Firebase部署错误:找不到模块&#39;@ babel / runtime / helpers / builtin / interopRequireDefault&#39; - Firebase deploy error: Cannot find module '@babel/runtime/helpers/builtin/interopRequireDefault' firebase 部署:错误解析触发器:找不到模块'path_to_project/functions' - firebase deploy: error parsing triggers: Cannot find module 'path_to_project/functions' 算法错误:找不到模块“ firebase” - Algolia-Error: Cannot find module 'firebase'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM