I set up a firebase functions project on visual studio code and inside the index.ts file I was unable to make it recognize the imported modules. The autocomplete shows that the modules exist, however when I import them I get the error "Cannot find module".
But the project compiles and passes the lint check. I just cannot use the intellisense. I tested the solutions below but cannot get it working;
npm install.Screenshots
The error

Folder structure

tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"]
},
"compileOnSave": true,
"include": ["src", "decs.d.ts"]
}
package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"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": "8"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^4.2.0",
"@google-cloud/storage": "^5.2.0",
"@types/multer": "^1.4.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-multipart-file-parser": "^0.1.2",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
"multer": "^1.4.2"
},
"devDependencies": {
"@types/cors": "^2.8.7",
"firebase-functions-test": "^0.2.0",
"tslint": "^5.12.0",
"typescript": "^3.8.0"
},
"private": true
}
Here is my use case.
in JS
const admin = require("firebase-admin")
const functions = require("firebase-functions")
in TS
import firebase from "firebase/app"
import "firebase/analytics"
import "firebase/auth"
import "firebase/storage"
in package.json
"dependencies": {
"firebase": "^7.17.1",
...
},
You can find official doc about ES2015 style import in the firebase document page https://firebase.google.com/docs/web/setup#add-sdks-initialize
ps. A screenshot is really helpful to describe your problem in general. Don't be care 🍻
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With