简体   繁体   English

类型错误:firebase.functions 不是函数

[英]TypeError: firebase.functions is not a function

I know someone else has posted this question before , but I believe mine has a right declaration and still doesn't work:我知道之前有人发布过这个问题,但我相信我的声明是正确的,但仍然不起作用:

Running the sendEmail.js:运行 sendEmail.js:

node sendEmail.js

Inside sendEmail.js:在 sendEmail.js 中:

"use strict";
// Initialize Function Caller App
const firebase = require("firebase");
// Required for side-effects
require("firebase/functions");

var config = {
  apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  authDomain: "my-project-id.firebaseapp.com",
  databaseURL: "https://my-project-id.firebaseio.com",
  projectId: "my-project-id",
  storageBucket: "my-project-id.appspot.com",
  messagingSenderId: "xxxxxxxxxx"
};
firebase.initializeApp(config);

var functions = firebase.functions(); // Error here: TypeError: firebase.functions is not a function

I got the above sample from the Firebase Documentation .我从Firebase 文档中获得了上述示例。 It works for my other project but not the current one.它适用于我的另一个项目,但不适用于当前的项目。 I've also run the following in my sendEmail.js folder:我还在我的sendEmail.js文件夹中运行了以下内容:

npm install firebase@5.10.1 --save

In my Firebase project root folder, my package.json file has the firebase-functions dependency too:在我的 Firebase 项目根文件夹中,我的package.json文件也具有firebase-functions依赖项:

"dependencies": {
    "firebase": "^5.10.0",
    "firebase-admin": "^7.3.0",
    "firebase-functions": "^2.3.0",
    "nodemailer": "^6.1.0"
  },

But FYI, my sendEmail.js is in the following folder:但仅供参考,我的sendEmail.js位于以下文件夹中:

project-root\testing\sendEmail.js
project-root\testing\node_modules\@firebase
project-root\testing\node_modules\@firebase\functions

And I still get this error:我仍然收到此错误:

var functions = firebase.functions();
                         ^
TypeError: firebase.functions is not a function
    at Object.<anonymous> (d:\project-root\testing\sendEmail.js:17:26)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

May I know what else do I need to check?我可以知道我还需要检查什么吗? Any help will be much appreciated, thank you!任何帮助将不胜感激,谢谢!

将以下导入行添加到包含您的 javascript 的 HTML 文件中:

<script src="/__/firebase/<version>/firebase-functions.js"></script>

The code you have was made to run in Cloud Functions for Firebase . 您已编写了可以在Cloud Functions for Firebase中运行的代码。 You can't simply run it in a local Node.js, as it depends on things that won't be available there. 您不能简单地在本地Node.js中运行它,这取决于那里不存在的功能。

To run the code in Cloud Functions, you have to deploy it to Google's servers with the firebase deploy command . 要在Cloud Functions中运行代码,您必须使用firebase deploy命令 将其部署到Google的服务器

To test the functions locally , use the firebase serve command. 在本地测试功能 ,请使用firebase serve命令。

暂无
暂无

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

相关问题 使用firebase的云功能:firebase.functions不是一个功能 - Cloud functions with firebase: firebase.functions is not a function Firebase 函数:类型错误:collectionRef.count 不是 function - Firebase functions: TypeError: collectionRef.count is not a function 类型错误:querySnapshot.forEach 不是 function - Firebase 云函数 - TypeError: querySnapshot.forEach is not a function - Firebase Cloud Functions TypeError:Firebase不是函数 - TypeError: Firebase is not a function 谷歌云功能 Firebase 使用 NodeJS 更新 FieldValue.increment(1) - TypeError: FieldValue.increment is not a function - Google cloud functions Firebase Update FieldValue.increment(1) using NodeJS - TypeError: FieldValue.increment is not a function 未处理的错误TypeError:使用forEach Firebase Cloud Functions时,snapshot.val不是函数 - Unhandled error TypeError: snapshot.val is not a function when using forEach Firebase Cloud Functions (..)。然后不是函数,firebase云功能 - (..).then is not a function ,firebase cloud functions 运行 Firebase 函数测试时“路径”中的类型错误 - TypeError in "path" when running Firebase Functions Test firebase-functions:未知错误状态:TypeError:db.collectionGroup不是函数 - firebase-functions: Unknown error status: TypeError: db.collectionGroup is not a function Firebase的云函数:“ TypeError:DialogflowApp不是构造函数” - Cloud Functions for Firebase: “TypeError: DialogflowApp is not a constructor”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM