Firebase-tools: Emulator fails on "firebase init" template with firebase-admin error.

Created on 12 May 2019  Â·  12Comments  Â·  Source: firebase/firebase-tools

[REQUIRED] Environment info

Firebase CLI: 6.9.2
Platform: macos, Windows

(Problem does not exist with CLI 6.8.0.)

[REQUIRED] Test case

Emulating the given HTTP trigger in a new project.

[REQUIRED] Steps to reproduce

  1. firebase init a new project space for Functions
  2. Take all the defaults, choose JavaScript
  3. Uncomment the code in index.js
  4. Emulate with either firebase emulators:start --only functions or firebase serve --only functions
  5. Access the given URL

[REQUIRED] Expected behavior

"Hello from Firebase!"

[REQUIRED] Actual behavior

See the message on emulator output:

âš   The Firebase Admin module has not been initialized early enough. Make sure you run "admin.initializeApp()" outside of any function and at the top of your code

The function will time out and disconnect as well. E.g:

curl: (52) Empty reply from server
emulator-suite bug

Most helpful comment

Thanks for the help, working on a fix which should be merged in today.

All 12 comments

same issue

same here

Add this in your index.ts file

    const admin = require('firebase-admin')

    try {
       admin.initializeApp()
     } catch (error) {
       //TODO: ignoring until firebase-functions fix released
    }

same issue

For everyone on this thread, are you all experiencing this on Windows or on other platforms as well?

Windows for me

Original issue states macos, Windows.

Gotcha, thanks missed that!

Windows

Firebase: 6.9.2
OS: macOS 10.14.3

Same here with Linux (Debian Stretch)
Firebase: 6.9.2
OS: Linux 4.19.26 x86_64

(setup is OK with @lionel95200x workaround)

Thanks for the help, working on a fix which should be merged in today.

Was this page helpful?
0 / 5 - 0 ratings