我有一个带有react-native-firebase的react native应用,我试图运行一个可调用的https firebase函数,该函数被部署到一个自定义区域。
我读到 firebase.app().functions("MY-REGION")
所以我尝试了以下内容。
import { firebase } from "@react-native-firebase/database"
import functions from "@react-native-firebase/functions"
firebase.app().functions("MY-REGION")
但是,如果我运行这个,我得到这个错误。
Error: You attempted to use
"firebase.app('[DEFAULT]').functions" but this
module could not be found.
Ensure you have installed and imported the
'@react-native-firebase/functions' package
"函数包已安装
如果我删除 @react-native-firebase/functions
导入时,错误依旧。
如何在我的网站上为firebase https函数指定区域?react-native-firebase
?
firebase.initializeApp({
...options
})
firebase.app().functions("MY-REGION")
And that says Error: Firebase App named '[DEFAULT]' already exists
firebase.initializeApp({
...options
}, "APP_NAME")
firebase.app("APP_NAME").functions("MY-REGION")
Gives Error: No firebase App 'APP_NAME' has been created - call firebase.initializeApp()
我希望我错过了一些琐碎的东西。
解决的办法是改变函数的导入方式 import functions from "..."
到 import "..."
:
import { firebase } from "@react-native-firebase/database"
import "@react-native-firebase/functions" // <--
// call a https firebase function
firebase.app().functions("MY-REGION").httpsCallable('MyFunction')()
注意: MY-REGION
应该设置为所选httpsCallable函数在firebase函数仪表板中显示的区域。
我找到的修复方法确实很简单...... 我把它分享到这里,以便对其他人有所帮助,但欢迎提出更好的解决方案。