My Firebase project utilizes TypeScript functions with the following directory structure:
- functions
- src
- index.ts
- shared
- other.ts
- tsconfig.json
- package.json
Within my tsconfig.json
file, the configuration is as follows:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"resolveJsonModule": true
},
"compileOnSave": true,
"include": [
"src"
]
}
Furthermore, in 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"
}
}
While I can successfully compile the project using npm run build
(equivalent to tsc -b
), I encounter an issue when attempting to serve (firebase emulators:start
). The error message states:
Error: Cannot find module './functions/lib/index.js'. Please verify that the package.json has a valid "main" entry
To my surprise, the lib
directory now contains two new folders: src
and shared
, instead of the expected compiled JS files directly under it. How can I address this issue?