首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >firebase函数:shell找不到自定义函数配置变量

firebase函数:shell找不到自定义函数配置变量
EN

Stack Overflow用户
提问于 2019-06-14 01:36:32
回答 1查看 746关注 0票数 2

我正尝试在本地测试我的云功能。我有一个自定义函数配置变量,所以我使用命令firebase functions:config:get > .runtimeconfig.json生成一个runtimeconfig.json文件:

代码语言:javascript
复制
{
  "stripe": {
    "testkey": "someKey"
  }
}

然后,我使用命令firebase functions:shell启动模拟器,但它在我的终端中输出以下错误:

代码语言:javascript
复制
+  functions: Emulator started at http://localhost:5001
!  TypeError: Cannot read property 'testkey' of undefined
    at Object.<anonymous> (C:\Users\Jesper\intergun\functions\lib\index.js:14:52)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:532:33
    at Generator.next (<anonymous>)
!  We were unable to load your functions code. (see above)
   - It appears your code is written in Typescript, which must be compiled before emulation.
   - You may be able to run "npm run build" in your functions directory to resolve this.

由于某种原因,它找不到变量,即使它指向生成的index.js文件,它似乎也认为代码是用TypeScript编写的。我试着运行npm run build,但结果是一样的。

我的index.ts顶部看起来像这样:

代码语言:javascript
复制
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import 'firebase-functions';
import * as Stripe from 'stripe';

admin.initializeApp();
const stripe = new Stripe(functions.config().stripe.testkey);

我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-14 03:18:57

我在这里找到了解决方案:https://github.com/firebase/firebase-tools/issues/711

为了生成.runtimeconfig.json,我使用了命令firebase functions:config:get > .runtimeconfig.json。然而,这生成了一个看起来是正确的文件,但显然包含了不应该存在的不可见字符。相反,我使用了这个命令:firebase functions:config:get | ac .runtimeconfig.json。这就解决了问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56585866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档