[英]Cannot run firebase functions on localhost using firebase emulator:start
我嘗試使用 firebase emulator:start 在本地計算機上測試我的 google firebase 雲功能。 然而,雲函數的本地實例沒有被執行,而是在谷歌雲上的實例被執行。
我按照以下步驟設置模擬器: https : //firebase.google.com/docs/functions/local-emulator
$ export GOOGLE_APPLICATION_CREDENTIALS='path/tofile'
$ firebase setup:emulators:firestore
$ firebase init firestore
$ export FIRESTORE_EMULATOR_HOST=localhost:8080
$ firebase emulators:start
Starting emulators: ["functions","firestore","hosting"]
⚠ Your requested "node" version "8" doesn't match your global version "10"
✔ functions: Emulator started at http://localhost:5001
i firestore: Logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
✔ hosting: Emulator started at http://localhost:5000
i hosting: Serving hosting files from: www
✔ hosting: Local server: http://localhost:5000
i functions: Watching "/home/borch/Documents/Ionic/myproject/functions" for Cloud Functions...
i functions: Setting up Cloud Firestore trigger "myGCFunction"
✔ functions: Trigger "myGCFunction" has been acknowledged by the Cloud Firestore emulator.
如您所見,雲 Firestore 模擬器識別了觸發器。
但是每次調用 myGCFunction 時都會執行的函數是 Google Cloud 上的函數。 我認為它應該從我在 localhost:8080 上運行的本地 API 執行該函數,對嗎?
我意識到只有雲上的函數被執行,因為我用該函數執行的新記錄檢查了 firebase 函數控制台。
我將 firebase-admin 和 firebase-functions 更新為最新版本:
$ cat functions/package.json | grep firebase-
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.2",
謝謝。
本地模擬器不會響應雲中的變化。 您必須實際更改本地模擬數據庫才能觸發本地模擬功能。
(想象一下,如果您不小心啟動了一個本地模擬器來響應繁忙的生產數據庫的更改 - 這將無法在您的本地機器上很好地擴展,是嗎?本地環境必須與任何雲托管環境完全隔離才能正常工作。 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.