While working with Typescript and firebase-admin for firebase cloud functions, I encountered the error message "Cannot find module 'firebase-admin/app'" when compiling the code with TS. Tried solutions:
- Reinstalling Dependency
- Deleting node_modules
The import line causing the issue:
import { initializeApp } from 'firebase-admin/app';
I also attempted changing the import to this syntax. Although TS did not raise any errors, Firebase Cloud function threw an error stating "cannot find module 'firebase-admin/app'".
const {initializeApp} = require('firebase-admin/app')
My Package.json details:
{
"name": "functions",
"scripts": {
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.14.1",
"moment": "^2.29.1",
"node-fetch": "2.6.7"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0"
},
"private": true
}
Here is my tsconfig.json configuration.
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"outDir": "lib",
"sourceMap": true,
"strict": false,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}