gpt4 book ai didi

Firebase 模拟器 : datasnapshot. ref 抛出 "Cannot parse Firebase url..."

转载 作者:行者123 更新时间:2023-12-04 04:06:57 24 4
gpt4 key购买 nike

背景

我有一个已在 firebase 实时环境中成功运行的应用程序,但是当我尝试在本地模拟器设置上运行它时,它失败了。

步骤

  1. 运行 firebase emulators:start --only functions,database,使用以下 firebase.json 配置:
{
"functions": {
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"ui": {
"enabled": true
},
"database": {
"port": 9000
}
},
"database": {
"rules": "database.rules.json"
}
}

2:打开模拟器UI,切换到“Realtime Database”选项卡,在schema中,创建一个“congregations”子节点,然后向其中添加一些子数据,例如:

{
"congregationName": "My Congregation",
"email": "test@test.com",
"newEventData": {"capacity":123,"eventName":"My Event"}
}
  1. 观察...

脚本(我将在下面粘贴)然后应该获取数据并进行一些进一步的处理、编辑和写入一些额外的数据。这在实时设置上运行良好,但在本地模拟器上没有任何反应,相反,我看到我的 firebase 终端出现错误。

代码+错误

我已经去掉了糟粕并将函数简化为仅包含错误代码:

exports.addCongregation = functions.database
.ref("/congregations/{congregationId}")
.onCreate(async (snap, context) => {
console.log(snap.val()); // runs fine, displays the entered data
console.low(snap.ref); // throws an error without logging anything else
});
  • console.log(snap.val()) 将按预期输出我在步骤 2 中输入的示例数据。
  • console.log(snap.ref) 不会向终端输出任何内容,除了抛出以下错误,堆栈跟踪指向 snap.ref 被称为:
!  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to GAC-staging.key.json. Non-emulated services will access production using these credentials. Be careful!
i functions: Beginning execution of "addCongregation"
> { congregationName: 'My Congregation',
> email: 'test@test.com',
> newEventData: { capacity: 123, eventName: 'My Event' } }
> [2020-06-10T18:38:45.980Z] @firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
! functions: Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at fatal (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\@firebase\database\dist\index.node.cjs.js:341:11)
at parseRepoInfo (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\@firebase\database\dist\index.node.cjs.js:1295:9)
at RepoManager.databaseFromApp (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\@firebase\database\dist\index.node.cjs.js:14986:25)
at Object.initStandalone (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\@firebase\database\dist\index.node.cjs.js:15377:45)
at DatabaseService.getDatabase (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\firebase-admin\lib\database\database.js:66:23)
at FirebaseApp.database (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\firebase-admin\lib\firebase-app.js:231:24)
at DataSnapshot.get ref [as ref] (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\firebase-functions\lib\providers\database.js:279:34)
at exports.addCongregation.functions.database.ref.onCreate (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\index.js:86:22)
at cloudFunction (C:\Users\Me\Projects\Web-Dev\prayin.io\functions\node_modules\firebase-functions\lib\cloud-functions.js:132:23)
at runFunction (c:\Users\Me\AppData\Local\Yarn\Data\global\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:553:20)
! Your function was killed because it raised an unhandled error.

我不知道为什么会这样,特别是考虑到我只在本地模拟器上遇到问题。任何帮助将非常感激。对于它的值(value),实时数据库选项卡顶部显示的 URL 是 http://localhost:9000/,这是有道理的,我不确定它与预期的 x 有何关系。 firebaseio.com 网址。

最佳答案

您似乎在 firebase-functions SDK 中发现了错误。我遇到了同样的事情并看到了您的帖子,以及他们存储库中的未解决问题。

https://github.com/firebase/firebase-functions/issues/726

听起来 bug 的来源已经确定,他们正在修复。

来自 firebase 的 samtstern:

We are working on a fix. The issue is with change.after.ref, and the workaround is to build your own ref to the document inside the function using admin.database().ref()...

关于Firebase 模拟器 : datasnapshot. ref 抛出 "Cannot parse Firebase url...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62310911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com