【问题标题】:Cloud Functions Emulator not logging things on console.log() on Cloud Firestore triggersCloud Functions Emulator 未在 Cloud Firestore 触发器上的 console.log() 上记录内容
【发布时间】:2020-04-18 13:19:19
【问题描述】:

我已成功运行 Firebase 模拟器:

E:\firebase>firebase emulators:start
i  emulators: Starting emulators: functions, firestore
!  Your requested "node" version "8" doesn't match your global version "10"
+  functions: Emulator started at http://localhost:5001
!  No Firestore rules file specified in firebase.json, using default rules.
i  firestore: Serving ALL traffic (including WebChannel) on http://localhost:808
0
!  firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and
 will go away soon. Please use port above instead.
i  firestore: Emulator logging to firestore-debug.log
+  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  functions: Watching "E:\firebase\func
tions" for Cloud Functions...
!  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to
 E:\firebase\key.json. Non-emulated serv
ices will access production using these credentials. Be careful!
+  functions[notifyNewMessage]: firestore function initialized.
+  All emulators started, it is now safe to connect.

带有notifyNewMessage函数的functions文件如下:

const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()

exports.notifyNewMessage = functions.firestore
    .document('test/{test}')
    .onCreate((docSnapshot, context) => {    
        console.log(docSnapshot.data())
    }

当我在 Firebase 控制台中手动创建新文档时,Windows 中的 CLI 不会记录任何内容。我该如何解决这个问题,以便它记录函数在我的 CLI 中所说的内容?

【问题讨论】:

    标签: google-cloud-platform google-cloud-firestore google-cloud-functions firebase-cli firebase-tools


    【解决方案1】:

    我只是一个白痴,并没有通过代码重新编译。

    【讨论】:

    • 使用哪个命令重新编译ts代码。
    • npm run build: tsc
    【解决方案2】:

    本地模拟器不会响应托管在 Google 云中且在控制台中可见的 Firestore 数据库中的更改。它确实响应的是也在您的计算机上运行的本地模拟 Firestore 数据库中的更改。如果您希望 Firestore 功能在本地模拟器中触发,则必须改为更改模拟的 Firestore,如 documentation 中所述。您可能需要通过提供的quickstart 来获得一些经验。

    如果你不想使用 Firestore 模拟器,只想直接触发它进行测试,可以使用Firebase CLI local shell

    【讨论】:

    • 谢谢!看来我只需要直接触发就可以测试了。
    猜你喜欢
    • 1970-01-01
    • 2018-10-16
    • 2018-03-27
    • 2020-02-04
    • 1970-01-01
    • 2021-05-04
    • 2021-11-09
    • 2018-03-23
    • 2018-02-17
    相关资源
    最近更新 更多