我正尝试在本地测试我的云功能。我有一个自定义函数配置变量,所以我使用命令firebase functions:config:get > .runtimeconfig.json
生成一个runtimeconfig.json
文件:
{
"stripe": {
"testkey": "someKey"
}
}
然后,我使用命令firebase functions:shell
启动模拟器,但它在我的终端中输出以下错误:
+ 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
顶部看起来像这样:
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);
我遗漏了什么?
https://stackoverflow.com/questions/56585866
复制相似问题