Kishan Oza
Kishan Oza

Reputation: 1735

firebase functions emulators not starting

as you all aware about firebase CLI's new feature which is local emulators explained here(https://firebase.googleblog.com/2020/05/local-firebase-emulator-ui.html?m=1)

so I have updated my CLI and when I run firebase emulators:start I get this error in my functions code

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.

can anyone help what I need to do here ??

Upvotes: 1

Views: 1732

Answers (2)

Greg Ennis
Greg Ennis

Reputation: 15379

I found that instead of calling:

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

I had to instead call:

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

This resolved the issue.

Upvotes: 1

Doug Stevenson
Doug Stevenson

Reputation: 317322

The error message is suggesting to you:

It appears your code is written in Typescript, which must be compiled before emulation.

You have to build the code first with npm run build. The emulator will not do that for you.

Upvotes: 1

Related Questions