随着Firebase云功能的最新更新,我在初始化应用程序以及数据库引用时遇到错误.
With the latest update of firebase cloud functions, I am getting errors while initializing app, as well as database ref.
第一个错误: 以下内容应基于Firebase函数v1.0文档和示例( github/firebase/friendlychat-web/blob/master/cloud-functions/functions/index.js )
First Error: Following should work based on Firebase functions v1.0 documentation and samples ( github/firebase/friendlychat-web/blob/master/cloud-functions/functions/index.js )
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); //this fails在上述代码的Firebase部署中,我收到以下错误:
I get following error on firebase deploy for above code:
Error: Error occurred while parsing your function triggers. Error: Failed to parse app options file: Error: ENOENT: no such file or directory, open '[object Object]' at FirebaseAppError.FirebaseError [as constructor] (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:39:28) at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:85:28) at new FirebaseAppError (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:119:28) at FirebaseNamespaceInternals.loadOptionsFromEnvVar (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:214:19) at FirebaseNamespaceInternals.initializeApp (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:64:28) at FirebaseNamespace.initializeApp (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:362:30) at Object.<anonymous> (/Users/ZZZ/dummy/functions/index.js:5:7) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32)如果我通过配置文件即可解决此错误(但这违反了Firebase文档)
This error is resolved if I pass the config file (but it goes against the firebase documentation)
const functions = require('firebase-functions'); const admin = require('firebase-admin'); var config = { apiKey: "<APIKEY>", authDomain: "<DOMAIN>", databaseURL: "<URL>", projectId: "<PROJECTID>", storageBucket: "<BUCKET>", messagingSenderId: "<ID>" }; admin.initializeApp(config);//this works第二个错误:当我按如下所示进行数据库ref调用时,它失败并给出错误:
Second Error:When I make database ref call as below , it fails and gives error:
const functions = require('firebase-functions'); const admin = require('firebase-admin'); var config = { apiKey: "<APIKEY>", authDomain: "<DOMAIN>", databaseURL: "<URL>", projectId: "<PROJECTID>", storageBucket: "<BUCKET>", messagingSenderId: "<ID>" }; const app = admin.initializeApp(config); exports.updateUserProfile = functions.database.ref('/UserProfile/{userid}') .onCreate((snapshot, context) => { console.log(snapshot.val()); });日志:
Running command: npm --prefix "$RESOURCE_DIR" run lint > functions@ lint /Users/ZZZ/dummy/functions > eslint . ✔ functions: Finished running predeploy script. i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading... Error: Unexpected token o in JSON at position 1推荐答案
由于错误在Firebase CLI 3.18.1版中. 尝试卸载当前版本并安装3.18.0,这应该可以解决该错误.
You are experiencing this error because of a bug in firebase CLI version 3.18.1. Try uninstalling the current version and install 3.18.0 and this should solve the error.
npm uninstall -g firebase-tools npm install -g firebase-tools@3.18.0更新: Firebase CLI版本3.18.2已发布,并且问题现在已解决.
UPDATE: Firebase CLI version 3.18.2 has been released and the issue is now resolved.
更多推荐
Cloud Functions Firebase v1.0无法初始化
发布评论