0
当我试图在我的本地火力模拟器部署一个功能,我得到这个错误本地部署Firebase的云端函数。 admin.initializeApp(functions.config())
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);
register.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功能https://stackoverflow.com/questions/42763951/run-firebase-cloud-functions-locally?rq=1 – louisvno
编辑帖子以包含索引。 js文件。 @DougStevenson –