大佬教程收集整理的这篇文章主要介绍了为什么我的 firebase 函数没有从运行时配置中读取我的 algolia 密钥?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在尝试测试我的 firebase 函数时,我不断收到当前错误。
Found .runtimeconfig.Json but the JsON format is invalID.
! TypeError: Cannot read property 'app' of undefined
at Object.<anonymous> (F:\Web Dev Stuff\SEEKIO\seekio\functions\index.Js:4:56)
at Module._compile (internal/modules/cJs/loader.Js:701:30)
at Object.Module._extensions..Js (internal/modules/cJs/loader.Js:712:10)
at Module.load (internal/modules/cJs/loader.Js:600:32)
at tryModuleLoad (internal/modules/cJs/loader.Js:539:12)
at Function.Module._load (internal/modules/cJs/loader.Js:531:3)
at Module.require (internal/modules/cJs/loader.Js:637:17)
at require (internal/modules/cJs/helpers.Js:22:18)
at initializeRuntime (C:\Users\msi\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.Js:680:29)
at process._tickCallback (internal/process/next_tick.Js:68:7)
! We were unable to load your functions code. (see above)
我的运行时配置如下所示:
当我删除配置文件并运行firebase functions:config:get > .runtimeconfig.Json
时,它只会返回这些变量和相同的文件格式,所以我有点困惑。
我的函数如下所示:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const algoliasearch = require("algoliasearch");
const clIEnt = algoliasearch(
functions.config().algolia.app,functions.config().algolia.key
);
const index = clIEnt.initIndex("Listings");
exports.createRecord = functions
.region("europe-west1")
.database.ref("/Listings/{ListingID}")
.onCreate((snap,context) => {
return index.saveObject({
objectID: snap.ID,...snap.data(),});
});
如果您使用 Powershell 调用此命令:
firebase functions:config:get > .runtimeconfig.json
文件 .runtimeconfig.json
是使用 UCS-2 LE BOM
编码创建的(Node 使用默认设置无法正确读取)。
改为使用这个使用 PowerShell 管道的命令:
firebase functions:config:get | sc .runtimeconfig.json
现在 .runtimeconfig.json
将使用预期的普通 UTF-8
编码。
注意: sc
是 Set-Content
cmdlet 的简写 - 用给定的内容写入文件(必要时替换文件)。 ac
(Add-Content
cmdlet)与此类似,但用于将内容附加到文件中。
以上是大佬教程为你收集整理的为什么我的 firebase 函数没有从运行时配置中读取我的 algolia 密钥?全部内容,希望文章能够帮你解决为什么我的 firebase 函数没有从运行时配置中读取我的 algolia 密钥?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。