You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Reacted by Dallas Phillips, Junior Usca, anya-ji, Niklas Lavrell, Christian Gogstad Eide, Alexis Rougnant, S. Suzuki, elzup, Sushant, Joshua Sosso (Deprecated) and 24 more
I have the same issue. For some reason, running npm install resolved the error when running mocha tests from a non-debug terminal instance in Visual Studio Code, but running mocha tests from a debug terminal instance still yields this error. The node_modules package is definitely installed.
Reacted by James Nisbet, Alan Ho, Jason Tian, Junior Usca, anya-ji, Christian Gogstad Eide, Peter Palmer, ibrahimkarahan, edenhermelin, Damianux and 5 more
Reacted by Edgar Rodriguez, Arshad Azaad, Brian Díaz, Sebastián Alejandro Blázquez Olivera, Justin De Burgo and Al Amin Khan
@shalbert94 Importing the top level module and then accessing internal things like you suggested works.
That is exactly the workaround that I proceeded with.
So, either the docs need updating, or the library itself does.
Edit – I can confirm that downgrading to v12 did solve the issue.
Assuming there are no other libraries, frameworks or custom module loaders in play, more likely explanation is your Node 17 setup was somehow loading an old version of firebase-admin (e.g. v9), that didn't have the new module exports. Changing to Node 12 pulled in the latest version of the library, and picked up the new entry points. Just a guess.
Confirming that using import firebaseAdmin from 'firebase-admin' resolves it, however that's a big headache. For now I've given up on this approach and gone back to using import Firestore from '@google-cloud/firestore' (and it looks like firebase-admin just wraps that anyway so no harm I guess?)
Reacted by vinzznv, Adarsh Madrecha, (Rew) Andrew McLagan and Bastien Grignon
I'll see about building a repro when I get some time, but I'm assuming it's related to Vite (using Vite + Sveltekit). Perhaps fixed by this hot-off-the-press PR vitejs/vite#5593? Or maybe it's this bug vitejs/vite#4340? Bit beyond my pay grade
We encountered the issue in Vite during alpha testing. See #1340 (also vitejs/vite#3953). It's a bug in their module resolver. We cannot do much about that on our end, but it sounds like the PR you've linked above is expected to fix it.
Other platforms with known issues include Jest and ESLint (see #1481)
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:
For some reason npm pulled v9 for me, I manually edited my package.json (remember it's the one in the functions folder): "firebase-admin": "^10.0.2",
All imports are working correctly now.
For anyone else looking for things to try, learn from my mistake. When upgrading to firebase-admin@10, I accidentally made it a dev dependency, thus triggering this error.
I did have the same issue with not finding the module 'firebase-admin/app'. Ended up accessing firebase products with suggestions from others at the top of this thread. Tried it again the default way from google docs , regardless of the error 'module not found' everything still works fine and able to use firebase product (firestore). You can IGNORE the error and run your code. I am node version 12
@jasonburrows If you are using the namespaces you should use firebaseAdmin.auth(app).
I ran a few tests and it seems like import * as firebaseAdmin from 'firebase-admin' imports all the named exports... so you specifically need to access the default export. I am unsure why this happens or what the correct fix for this. I will need to investigate the issue further.
import * as firebaseAdmin from 'firebase-admin';
const auth = firebaseAdmin.default.auth();
This issue seems to be still ongoing, I get this when trying to deploy:
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8542
Error: Cannot find module 'firebase-admin/app'
Require stack:
- /myProject/functions/lib/functions/src/index.js
- /myProject/functions/node_modules/firebase-functions/lib/runtime/loader.js
- /myProject/functions/node_modules/firebase-functions/lib/bin/firebase-functions.js
at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1057:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1062:22)
at Function._load (node:internal/modules/cjs/loader:1211:37)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Module.require (node:internal/modules/cjs/loader:1487:12)
at require (node:internal/modules/helpers:135:16)
at Object.<anonymous> (/myProject/functions/lib/functions/src/index.js:7:15)
at Module._compile (node:internal/modules/cjs/loader:1730:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/myProject/functions/lib/functions/src/index.js',
'/myProject/functions/node_modules/firebase-functions/lib/runtime/loader.js',
'/myProject/functions/node_modules/firebase-functions/lib/bin/firebase-functions.js'
]
}
I do have latest version of firebase-admin installed:
Activity
google-oss-bot commentedon Nov 7, 2021
I found a few problems with this issue:
shalomhalbert commentedon Nov 7, 2021
I have the same issue. For some reason, running
npm installresolved the error when running mocha tests from a non-debug terminal instance in Visual Studio Code, but running mocha tests from a debug terminal instance still yields this error. Thenode_modulespackage is definitely installed.shalomhalbert commentedon Nov 7, 2021
Solved it by ignoring the import recommendation. Instead of
I am now using what existed before v10:
hiranya911 commentedon Nov 8, 2021
Code given above worked fine when executed through Node.js 12. Here's the output of the execution with an added
console.logstatement:Also I can do the following on a Node.js REPL:
May be somebody can share a minimal and complete repro of the issue? Something that we can download and run to repro the problem?
sankalpsans commentedon Nov 9, 2021
@hiranya911 I am currently using node
v17.0.1. Is it known to not work with this? Is the solution to downgrade to v12 instead?Edit – I can confirm that downgrading to v12 did solve the issue.
sankalpsans commentedon Nov 9, 2021
@shalbert94 Importing the top level module and then accessing internal things like you suggested works.
That is exactly the workaround that I proceeded with.
So, either the docs need updating, or the library itself does.
hiranya911 commentedon Nov 9, 2021
Works fine on Node 17 too:
This is most likely a problem specific to your environment/implementation. We will need a complete, minimal repro to know for sure.
As fas as our library is concerned, we correctly declare the new module entry points in our
package.jsonfile:firebase-admin-node/package.json
Lines 106 to 111 in b26501b
All Node.js versions 12 and up, should support it.
hiranya911 commentedon Nov 9, 2021
Assuming there are no other libraries, frameworks or custom module loaders in play, more likely explanation is your Node 17 setup was somehow loading an old version of firebase-admin (e.g. v9), that didn't have the new module exports. Changing to Node 12 pulled in the latest version of the library, and picked up the new entry points. Just a guess.
hiranya911 commentedon Nov 9, 2021
I pushed a copy of my attempt to repro this issue to https://github.com/firebase/firebase-admin-node/tree/hkj-repro-1488/nodetest. Feel free to play with it and see if you can still repro the problem.
Bandit commentedon Nov 9, 2021
I'm also getting this error when using the snippet provided:
=>
Error: Cannot find module 'firebase-admin/app'Node v14.16.1
Confirming that using
import firebaseAdmin from 'firebase-admin'resolves it, however that's a big headache. For now I've given up on this approach and gone back to usingimport Firestore from '@google-cloud/firestore'(and it looks likefirebase-adminjust wraps that anyway so no harm I guess?)hiranya911 commentedon Nov 9, 2021
@Bandit can you share a complete repro with us? Something similar to the complete example I've shared above in my last comment.
hiranya911 commentedon Nov 9, 2021
Folks who are seeing this error also please check their library version using one of the following methods:
Using
npm lsDirectly checking the
package.jsonof the libraryIf the version is indeed 10.x or higher, please share a complete repro that we can run.
Bandit commentedon Nov 9, 2021
Confirmed I'm using
firebase-admin@10.0.0I'll see about building a repro when I get some time, but I'm assuming it's related to Vite (using Vite + Sveltekit). Perhaps fixed by this hot-off-the-press PR vitejs/vite#5593? Or maybe it's this bug vitejs/vite#4340? Bit beyond my pay grade
hiranya911 commentedon Nov 9, 2021
We encountered the issue in Vite during alpha testing. See #1340 (also vitejs/vite#3953). It's a bug in their module resolver. We cannot do much about that on our end, but it sounds like the PR you've linked above is expected to fix it.
Other platforms with known issues include Jest and ESLint (see #1481)
14 remaining items
HelderSi commentedon 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:
That worked for me.
And just to note, my tsconfig.json is like this:
alxcholley commentedon Jan 24, 2022
Hi,
See that : https://firebase.google.com/docs/admin/migrate-node-v10#es-modules-support
fflores97 commentedon Jan 26, 2022
Similarly to @HelderSi, I had to do a moduleNameMapper config, but I'm using yarn v2 PnP, so my config looks like this:
Enragedsaturday commentedon Feb 2, 2022
For some reason npm pulled v9 for me, I manually edited my package.json (remember it's the one in the functions folder):
"firebase-admin": "^10.0.2",All imports are working correctly now.
artstylee commentedon Feb 2, 2022
backend package json
node version

v16.13.1firebase library package.json
"version": "10.0.2",
mattisx commentedon Feb 18, 2022
Deleting node_modules, package-lock.json, and running
npm cache clean --forcefixed this for me on Node 16.14.Benjamin-Lee commentedon Mar 9, 2022
For anyone else looking for things to try, learn from my mistake. When upgrading to firebase-admin@10, I accidentally made it a dev dependency, thus triggering this error.
Muhkol commentedon Mar 12, 2022
I did have the same issue with not finding the module 'firebase-admin/app'. Ended up accessing firebase products with suggestions from others at the top of this thread. Tried it again the default way from google docs , regardless of the error 'module not found' everything still works fine and able to use firebase product (firestore). You can IGNORE the error and run your code. I am node version 12
lneninger commentedon Mar 25, 2022
@Benjamin-Lee that fixed my issue. Thanks for share your error resolution.
fbukevin commentedon Jun 14, 2022
This issue is still not solved. Either I use node version 14.6.0 (npm v7.8.0) or version 18.1.0 (npm v8.8.0).
March-mitsuki commentedon Dec 7, 2022
I'm using node v18.12.0 with yarn and vscode. Runing
yarn cache clean --allthen reinstallingyarn install, and restarting vsode fixed this for me.jasonburrows commentedon Mar 9, 2023
Still experiencing this with firebase-admin@11.5.0 and node@18.15.0.
Clearing the cache and re-installing did not help.
I have tried the general import:
import * as firebaseAdmin from 'firebase-admin';...but I can't get at the
getAuthfunction.const auth = firebaseAdmin.auth.getAuth(app);Gives:
Property 'getAuth' does not exist on type '(app?: App | undefined) => Auth'.
lahirumaramba commentedon Mar 9, 2023
@jasonburrows If you are using the namespaces you should use
firebaseAdmin.auth(app).I ran a few tests and it seems like
import * as firebaseAdmin from 'firebase-admin'imports all the named exports... so you specifically need to access thedefaultexport. I am unsure why this happens or what the correct fix for this. I will need to investigate the issue further.In the meantime, I would also suggest using the new modular syntax:
https://firebase.google.com/docs/admin/migrate-node-v10
KariNarhi28 commentedon Aug 6, 2025
This issue seems to be still ongoing, I get this when trying to deploy:
I do have latest version of firebase-admin installed:
Initialization:
I tried removing package-lock.json and node_modules and reinstall, but it didn't help.
KariNarhi28 commentedon Aug 7, 2025
OK, I think I managed to fix this on my own laptop.
Check your whole path under where you keep your code for any special letters or symbols.
Especially umlaut letters like ö, ä, ü.
I had an ö-letter in my path on a top level so I changed the name to something else and now the deploy works.
Might not be the actual reason but I was getting the mentioned error and after changing the project-path, it no longer gives error.