【问题标题】:Deploying Cloud Functions for Firebase locally. admin.initializeApp(functions.config())在本地部署 Cloud Functions for Firebase。 admin.initializeApp(functions.config())
【发布时间】:2017-05-25 21:48:36
【问题描述】:

当我尝试在本地 Firebase 模拟器上部署功能时,出现此错误

ERROR: Function load error: Code could not be loaded.
ERROR: Does the file exists? Is there a syntax error in your code?
ERROR: Detailed stack trace: /home/krishna/whozoo-firebase-web/functions/node_modules/firebase-functions/lib/config.js:51
        throw new Error('Firebase config variables are not available. ' +
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
    at init (/home/krishna/whozoo-firebase-web/functions/node_modules/firebase-functions/lib/config.js:51:15)
    at Object.config (/home/krishna/whozoo-firebase-web/functions/node_modules/firebase-functions/lib/config.js:29:9)
    at Object.<anonymous> (/home/krishna/whozoo-firebase-web/functions/index.js:7:31)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
ERROR: Error: Failed to deploy function.
    at exec (/usr/local/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:135:18)
    at ChildProcess.exithandler (child_process.js:213:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

然后我在删除这行特定代码后重试部署

admin.initializeApp(functions.config())

我的功能已成功部署,但当我到达端点时,我会收到此消息

{"code": "app/no-app","message": "The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services."}

我该如何解决这个错误?

编辑

'use strict';

const admin = require('firebase-admin');
const functions = require('firebase-functions');
const register = require('./register');

admin.initializeApp(functions.config());

exports.register = functions.https.onRequest(register.registerHandler);

注册.js

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const cors = require('cors')

cors(req, res, () => {
let requestBody = req.body;

admin.auth().createUser({
        'email': requestBody.email,
        'emailVerified': false,
        'password': requestBody.password,
        'displayName': requestBody.firstName + ' 
        ' +requestBody.lastName
    });
});

这是我认为导致问题的 register.js 部分。 register.js 的其余部分包含响应消息。

【问题讨论】:

  • 你能展示一个导致问题的最小 index.js 吗?
  • 根据这篇文章,目前尚无法在本地部署 Firebase 功能stackoverflow.com/questions/42763951/…
  • 编辑帖子以包含 index.js 文件。 @DougStevenson
  • 您没有显示“./register”模块中的内容。
  • 我已经添加了 register.js 模块。发生此错误是否因为 admin.auth().createUser() 是 firebase 上的 API,并且无法将其带到本地模拟器? @DougStevenson

标签: firebase google-cloud-platform google-cloud-functions


【解决方案1】:

而不是这个:

admin.initializeApp(functions.config());

试试这个:

admin.initializeApp();

另外,把那一行放在之前你需要你的注册模块。

【讨论】:

    猜你喜欢
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2018-06-17
    • 2018-03-15
    • 2017-08-08
    相关资源
    最近更新 更多