My Firebase project has TypeScript functions implemented with the following directory hierarchy:
- functions
- src
- index.ts
- shared
- other.ts
- tsconfig.json
- package.json
My tsconfig.json
file looks like:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"resolveJsonModule": true
},
"compileOnSave": true,
"include": [
"src"
]
}
And my package.json
:
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc -b",
"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",
"test": "mocha --reporter spec 'test/**/*.ts'"
},
"engines": {
"node": "12"
},
"main": "lib/index.js",
"dependencies": {
"dep": "^1.0.0"
}
}
I'm able to compile the project with npm run build
(which translates to tsc -b
), but can't serve (firebase emulators:start
) due to the following error:
Error: Cannot find module './functions/lib/index.js'. Please verify that the package.json has a valid "main" entry
To my surprise, the lib
folder contains two new src
& shared
folders instead of the "compiled" JS directly under it. How can I fix it?