【问题标题】:firebase functions emulators not startingfirebase 功能模拟器未启动
【发布时间】:2020-09-09 15:54:55
【问题描述】:

大家都知道 firebase CLI 的新功能,即此处解释的本地模拟器 (https://firebase.googleblog.com/2020/05/local-firebase-emulator-ui.html?m=1)

所以我更新了我的 CLI,当我运行 firebase emulators:start 时,我的函数代码中出现此错误

kishan@kishans-Air functions % firebase emulators:start
i  emulators: Starting emulators: functions
⚠  Your requested "node" version "8" doesn't match your global version "10"
⚠  hosting: The hosting emulator is configured but there is no hosting configuration. Have you run firebase init hosting?
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "/Users/kishan/Desktop/dilip/googlecloudfunctions/functions" for Cloud Functions...
⚠  TypeError: Cannot convert object to primitive value
    at Proxy.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:311:83)
    at Object.<anonymous> (/Users/kishan/Desktop/dilip/googlecloudfunctions/functions/lib/index.js:7:7)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:661:33
⚠  We were unable to load your functions code. (see above)
   - It appears your code is written in Typescript, which must be compiled before emulation.

任何人都可以帮助我在这里需要做的事情吗?

【问题讨论】:

    标签: firebase google-cloud-functions firebase-tools


    【解决方案1】:

    错误信息提示你:

    您的代码似乎是用 Typescript 编写的,必须在仿真前编译。

    您必须先使用npm run build 构建代码。模拟器不会为您执行此操作。

    【讨论】:

    • 这不是这里的问题,我有同样的问题,我已经编译了打字稿。 functionsEmulatorRuntime 有问题 - 它试图控制台记录一个空对象,这会导致此错误。似乎是 functions.config().firebase 在模拟器中不起作用。
    • functions.config().firebase 已弃用。如果您没有 Firebase Admin SDK 的特定配置,则只需调用不带参数的 initalizeApp 即可为您的项目采用默认设置。
    【解决方案2】:

    我发现不是调用:

    admin.initializeApp(functions.config().firebase)
    

    我不得不打电话:

    admin.initializeApp({
        credential: admin.credential.applicationDefault()
    });
    

    这解决了问题。

    【讨论】:

      猜你喜欢
      • 2019-12-23
      • 2020-01-19
      • 1970-01-01
      • 2018-05-21
      • 2020-09-20
      • 2019-12-30
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多