Cloud Functions Firebase v1.0无法初始化

编程入门 行业动态 更新时间:2024-10-17 14:20:35
本文介绍了Cloud Functions Firebase v1.0无法初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

随着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无法初始化

本文发布于:2023-11-07 05:57:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   Functions   Cloud   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!