firebase-functions: Typescript compilation error: Argument of type 'Express' is not assignable [..]

Version info

node v10.16.0

firebase-functions: ^3.3.0

firebase-tools: 7.8.1

express ^4.17.1

Test case

import * as functions from 'firebase-functions';
import * as express from 'express';

const app = express();
export const api = functions.https.onRequest(app);

Steps to reproduce

Add the test case in an Typescript enable environment

Expected behavior

The onRequest handler should not throw Typescript compilation errors

Actual behavior

Typescript compilation error:

error TS2345: Argument of type 'Express' is not assignable to parameter of type '(req: Request, resp: Response) => void'.
  Types of parameters 'req' and 'req' are incompatible.

Were you able to successfully deploy your functions?

Yes, when I ignore typescript by casting it as <any> it deploys and runs as expected:

export const api = functions.https.onRequest(<any>app);

This is only a typing issue.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 22
  • Comments: 24 (1 by maintainers)

Most upvoted comments

Same issue with firebase-functions 3.6.0.

I’ve upgraded to firebase-functions from 3.3.0 to 3.6.0 and now also have this issue. I managed to fix it with any, but it’s not ideal.

I have fixed my firebase import to 3.3.0 in packages.json.

"firebase-functions": "3.3.0",

followed by a npm update solved it for now. But this is confirmed an issue with the ^3.6.0 version.

After some research, installing “@types/node”: “^14.0.1” solve the problem for me. Be careful to install this specific version, I’ve tried with the latest versions but seems like doing nothing. I’m serving Express on Cloud Functions to SSR and my package.json looks like the following:

{
  "name": "functions",
  "scripts": {
    "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": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
  },
  "devDependencies": {
    "@types/express": "^4.17.13",
    "@types/express-serve-static-core": "^4.17.24",
    "@types/node": "^14.0.1",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^4.1.5"
  },
  "private": true
}

Hey! Any updates? Thanks a lot!

Same issue with firebase-functions 3.7.0

Still seeing this with firebase-functions 3.7.0. Really wanting to update for the Node 10 improvements (considering all the Google libraries rapidly dropping support for Node 8 😅)

Does anyone have any new discoveries that could point us in a direction for where to start looking to get this fixed?

OK. I try several times remove node_modules folder and package-lock.json. Have no idea why but now it works. Probably I did some mistake with removing and install updated package.json .