[英]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.