TypeError:firebase.functions不是函数 [英] TypeError: firebase.functions is not a function

查看:32
本文介绍了TypeError:firebase.functions不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道其他人已经发布了此问题之前,但我相信我的声明正确,但仍然行不通:

I know someone else has posted this question before, but I believe mine has a right declaration and still doesn't work:

运行sendEmail.js:

node 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

我从 Firebase文档中获得了上述示例.它适用于我的其他项目,但不适用于当前项目.我还在 sendEmail.js 文件夹中运行了以下命令:

I got the above sample from the Firebase Documentation. It works for my other project but not the current one. I've also run the following in my sendEmail.js folder:

npm install firebase@5.10.1 --save

在我的Firebase项目根文件夹中,我的 package.json 文件也具有 firebase-functions 依赖项:

In my Firebase project root folder, my package.json file has the firebase-functions dependency too:

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

但是,仅供参考,我的 sendEmail.js 在以下文件夹中:

But FYI, my sendEmail.js is in the following folder:

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

我仍然收到此错误:

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文件中:

Add into the HTML file that includes your javascript the following import line:

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

这篇关于TypeError:firebase.functions不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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