Type error: Cannot find module 'firebase-functions' or its corresponding type declarations when deploying in Vercel

Viewed 401

I have a nextjs and firebase app setup with functions and everything runs and builds perfectly locally. However when I build and deploy to Vercel I get the following build error in Vercel console:

Type error: Cannot find module 'firebase-functions' or its corresponding type declarations.

enter image description here

here's my app/functions package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "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": {
    "axios": "^0.26.1",
    "firebase": "^9.6.11",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.18.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.25.4",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^4.5.4"
  },
  "private": true
}
1 Answers

I solved this by modifying the file tsconfig.json. I added "functions" to the "exclude" array.

"exclude": ["node_modules", "functions"]
Related