Я пытаюсь проверить свои облачные функции локально. У меня есть переменная конфигурации пользовательских функций, поэтому я использовал команду 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.
По какой-то причине он не может найти переменную, и кажется, что он думает, что код написан на TypeScript, даже если он указывает на сгенерированный файл index.js
. Я попытался запустить 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);
Чего мне не хватает?