【发布时间】:2021-07-04 08:28:52
【问题描述】:
我们正在尝试在发布我们的 firebase 函数之前创建一个开发环境。
我们已经成功安装并启动了一个本地模拟器,可以访问我们的 firestore 数据库,可以调用 HTTPS 端点和一切。开始firebase emulators:start 显示:
firebase emulators:start --import=./testdata
i emulators: Starting emulators: functions, firestore, hosting, pubsub
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database
⚠ Your requested "node" version "12" doesn't match your global version "14"
i firestore: Importing data from /home/forest/projects/icell/i_cell_parking_manager/firebase/testdata/firestore_export/firestore_export.overall_export_metadata
i firestore: Firestore Emulator logging to firestore-debug.log
i pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i hosting: Serving hosting files from: webserver
✔ hosting: Local server: http://localhost:5000
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "..../firebase/functions" for Cloud Functions...
✔ functions[createParkingReservationsForNextWeek]: pubsub function initialized.
✔ functions[reserveSpaceForUser]: http function initialized (http://localhost:5001/i-cell-parking-manager-backend/us-central1/reserveSpaceForUser).
┌────────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! View status and logs at localhost:4000 │
└────────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬──────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼──────────────────────────┤
│ Functions │ localhost:5001 │ localhost:4000/functions │
├───────────┼────────────────┼──────────────────────────┤
│ Firestore │ localhost:8080 │ localhost:4000/firestore │
├───────────┼────────────────┼──────────────────────────┤
│ Hosting │ localhost:5000 │ n/a │
├───────────┼────────────────┼──────────────────────────┤
│ Pub/Sub │ localhost:8085 │ n/a │
└───────────┴────────────────┴──────────────────────────┘
Other reserved ports: 4400, 4500
我们有一个名为 createParkingReservationsForNextWeek 的函数,它是一个定时的单个 pubsub,我们希望在不需要等待调度程序的情况下触发它。
*/
exports.createParkingReservationsForNextWeek = functions.pubsub
.schedule(WEEKLY_NOTIFICATION_SCHEDULE)
.timeZone(TIMEZONE_EUROPE_BUDAPEST)
....
根据https://firebase.google.com/docs/functions/local-emulator#web,我们可以通过在浏览器中导航到此 URL 来做到这一点:http://localhost:5001/i-cell-parking-manager-backend/us-central1/createParkingReservationsForNextWeek
但是我们得到这个错误(也可以在模拟器日志中看到):
functions: TypeError: Cannot read property 'data' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:580:28
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
at __awaiter (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:4:12)
at processBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:577:12)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:673:23
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
⚠ Your function was killed because it raised an unhandled error.
在日志中(http://localhost:4000/logs):
14:50:31
I
function[createParkingReservationsForNextWeek]
Beginning execution of "createParkingReservationsForNextWeek"
14:50:31
W
function[createParkingReservationsForNextWeek]
TypeError: Cannot read property 'data' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:580:28
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
at __awaiter (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:4:12)
at processBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:577:12)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:673:23
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
14:50:31
W
function[createParkingReservationsForNextWeek]
Your function was killed because it raised an unhandled error.
Cloud-firestore-emulator 版本为v1.11.9。
【问题讨论】:
标签: firebase google-cloud-firestore