1

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?

2
  • after tsc, check the contents of lib folder Commented May 23, 2021 at 11:26
  • As I've writted, the content is two directories (src & shared), with src containing index.js. Commented May 23, 2021 at 11:31

1 Answer 1

0

in package.json you will need to add the following

"main": "lib/src/index.js",

This is because of the two folders, as you have mentioned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.