question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module 'firebase-admin/app'

See original GitHub issue

package.json requirements look like this –

  "dependencies": {
    "@sentry/node": "^5.30.0",
    "body-parser": "1.19.0",
    "express": "^4.17.1",
    "firebase-admin": "10.0.0",
    "mysql": "^2.18.1",
    "pug": "3.0.2"
  }

node_modules has the corresponding module in the path ~/node_modules/firebase-admin/lib/app

Node code reads as –

const initializeApp  = require('firebase-admin/app');

And when the app is run, the following stacktrace emerges.

 Error: Cannot find module 'firebase-admin/app'
     at Function.Module._resolveFilename (module.js:547:15)
     at Function.Module._load (module.js:474:25)
     at Module.require (module.js:596:17)
     at require (internal/module.js:11:18)
     at Object.<anonymous> (/var/www/html/project/backend/main.js:16:24)
     at Module._compile (module.js:652:30)
     at Object.Module._extensions..js (module.js:663:10)
     at Module.load (module.js:565:32)
     at tryModuleLoad (module.js:505:12)
     at Function.Module._load (module.js:497:3)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:24
  • Comments:37 (9 by maintainers)

github_iconTop GitHub Comments

19reactions
shalomhalbertcommented, Nov 7, 2021

Solved it by ignoring the import recommendation. Instead of

'use strict';

const { initializeApp } = require('firebase-admin/app');
const { getFirestore, Timestamp, GeoPoint } = require('firebase-admin/firestore');

exports.initializeApp = () => initializeApp();
exports.getFirestore = () => getFirestore();
exports.Timestamp = Timestamp;
exports.GeoPoint = GeoPoint;

I am now using what existed before v10:

'use strict';

const firebaseAdmin = require('firebase-admin');

exports.initializeApp = () => firebaseAdmin.initializeApp();
exports.getFirestore = () => firebaseAdmin.firestore();
exports.Timestamp = firebaseAdmin.firestore.Timestamp;
exports.GeoPoint = firebaseAdmin.firestore.GeoPoint;
8reactions
HelderSicommented, Jan 9, 2022

I started to use firebase-admin@^10.0.1 and I had this error when running jest tests. It couldn’t map “firebase-admin/app” to “firebase-admin/lib/app” as expected. So I have mapped this manually on jest.config.ts:

import { pathsToModuleNameMapper } from 'ts-jest/utils';
import { compilerOptions } from './tsconfig.json';

...
export default {
 ...
 moduleNameMapper: pathsToModuleNameMapper(
    {
      ...compilerOptions.paths,
      'firebase-admin/*': ['node_modules/firebase-admin/lib/*'],
    },
    {
      prefix: '<rootDir>',
    },
  ),
...
}

That worked for me.

And just to note, my tsconfig.json is like this:

{
  "compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
      "modules/*": [
        "src/modules/*"
      ],
      "shared/*": [
        "src/shared/*"
      ],
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

FIrebase deploy error: Cannot find module 'firebase-admin'
I went to the functions directory and ran yarn (or npm install if you are old-school). Then went back to my project directory...
Read more >
Error: Cannot find module 'firebase-admin' - Google Groups
So I have new Firebase/Firestore project for Cloud Functions, and I have my index.js ... Detailed stack trace: Error: Cannot find module 'firebase-admin'....
Read more >
firebase-admin - npm
Firebase provides the tools and infrastructure you need to develop your app, grow your user base, and earn money. The Firebase Admin Node.js...
Read more >
Deploy fails with "Cannot find module 'firebase-admin' " even ...
I normally have a db.js function, which uses firebase-admin to read/write. Now when deploying (via git push) I keep getting deployment failures ...
Read more >
Add the Firebase Admin SDK to your server - Google
Note: The Realtime Database API in the Go Admin SDK currently does not ... To use the module in your application, require it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found