Firebase部署错误-找不到模块"firebase" [英] Firebase deploy error - Cannot find module 'firebase'

查看:212
本文介绍了Firebase部署错误-找不到模块"firebase"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署从数据库事件触发的Google Cloud函数触发器,但是当我运行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

当我第一次创建项目时,我可以部署功能而没有任何问题.自上次部署任何东西以来已经过了几天,但现在我在所有功能(不仅仅是触发器功能)上都遇到了这个问题

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)

我的功能:

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

Package.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:

firebase的错误消息:

Error messages from 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"}

我见过一些帖子,其中有些人缺少一些模块,需要在functions文件夹中运行npm i XXX,但是我没有见过任何有人说找不到Firebase模块的实例,而且我不确定自上次成功部署后会发生什么变化,或者我可能缺少的模块.

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.

推荐答案

找出解决方案.我没有在功能文件夹中安装firebase模块,但已将其包含在functions的父文件夹中.我进入功能并运行npm install --save 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. I went into functions and ran npm install --save firebase and the deploy was successful.

这篇关于Firebase部署错误-找不到模块"firebase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆