Home > Mobile >  How to use `firebase-admin` inside firebase functions using ES2015
How to use `firebase-admin` inside firebase functions using ES2015

Time:04-29

Nothing I do here seems to work, I can't find an example anywhere that actually seems correct

This:

import { initializeApp } from 'firebase-admin/app';

Throws:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '\path\to\my-proj\functions\node_modules\firebase-admin\app' imported from \path\to\my-proj\functions\index.js

This:

import * as admin from "firebase-admin";
admin.initializeApp();

Throws:

TypeError: admin.initializeApp is not a function

my functions' package.json looks like:

  "dependencies": {
    "firebase-admin": "^9.12.0",
    "firebase-functions": "^3.20.1"
  },

Whats going on, whats the correct syntax?

CodePudding user response:

You're using code samples meant for version 10 of firebase-admin, whereas you have version 9 installed. Read this for more information and run npm install firebase-admin@latest to get the latest version 10.1.0.

  • Related