firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

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

Open remie opened this issue 5 years ago โ€ข 23 comments

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.

remie avatar Nov 26 '19 15:11 remie

abra o caminho: functions>src no terminal de comando e faรงa um npm install --save express

HiddenBehindTheKeyBoard avatar Feb 15 '20 00:02 HiddenBehindTheKeyBoard

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.

kossnocorp avatar Apr 12 '20 17:04 kossnocorp

Same issue with firebase-functions 3.6.0.

jpinilloslr avatar Apr 17 '20 10:04 jpinilloslr

Likewise since updating to the latest version of firebase-functions. I was previously on 3.3.0.

brendanmc6 avatar May 03 '20 02:05 brendanmc6

I am also experiencing the same issue after upgrading firebase-functions from 3.3.0 to 3.6.1

dcgudeman avatar May 08 '20 22:05 dcgudeman

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.

Arno-Z avatar May 12 '20 08:05 Arno-Z

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?

kimroen avatar Jun 23 '20 08:06 kimroen

Same issue with firebase-functions 3.7.0

AlpSha avatar Jun 23 '20 16:06 AlpSha

i had to rollback to node 8 and my old firebase-functions and firebase-admin that was specified in package-lock. Couldn't get this working for now... will come back to it later.

partriv avatar Jul 07 '20 04:07 partriv

I just wanted to chime in here and mention that we were able to get past this now. In our case, it turned out that with the latest firebase-admin and firebase-functions, we weren't getting this error any more. However, we were getting other Express-related type errors because of a change to how parameter queries are typed, so we were just assuming the build failures were the same as before.

I would strongly suggest that you try this again and have a proper look at the error messages to make sure that you are actually still seeing this specific error.


๐Ÿ“ Here is the error we were seeing - it's likely you'll run into this

kimroen avatar Jul 09 '20 08:07 kimroen

this export const api = functions.https.onRequest(app); not work for me. Even do this still getting error. `node_modules/firebase-functions/lib/apps.d.ts:33:21 - error TS7033: Property 'firebaseArgs' implicitly has type 'any', because its get accessor lacks a return type annotation.

33 private get firebaseArgs(); ~~~~~~~~~~~~

node_modules/firebase-functions/node_modules/@types/express/index.d.ts:103:54 - error TS2315: Type 'Response' is not generic.

103 export interface Response<ResBody = any> extends core.Response<ResBody> { }`

lubo08 avatar Jul 14 '20 17:07 lubo08

@lubo08 Could you try doing a ls-command to check which version of the express types you are running?

npm ls "@types/express"

kimroen avatar Jul 14 '20 17:07 kimroen

functions@ /Users/..../workspace/sinvoicescloud/functions โ”œโ”€โ”ฌ @types/[email protected] โ”‚ โ””โ”€โ”€ @types/[email protected] โ””โ”€โ”ฌ [email protected] โ””โ”€โ”€ @types/[email protected]

lubo08 avatar Jul 14 '20 17:07 lubo08

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 .

lubo08 avatar Jul 14 '20 18:07 lubo08

@lubo08 Great to hear! What does the ls command say now?

kimroen avatar Jul 14 '20 18:07 kimroen

@kimroen looks same for firebase-functions, maybe @types/cors with different version cause troubles? @types/[email protected] โ”‚ โ””โ”€โ”€ @types/[email protected] โ””โ”€โ”ฌ [email protected] โ””โ”€โ”€ @types/[email protected]

lubo08 avatar Jul 14 '20 18:07 lubo08

@lubo08 Yes, I think that is likely. Thanks!

kimroen avatar Jul 14 '20 19:07 kimroen

Any update?

HathTech avatar Sep 01 '20 04:09 HathTech

Any updates to this?

patrickgorrell avatar Oct 07 '20 05:10 patrickgorrell

    npm i --save-dev @types/[email protected] @types/[email protected] typescript@^4.0.2 
    npm i --save express@^4.17.1 firebase@^7.19.1 firebase-functions@^3.11.0
    npm uninstall --save-dev @types/cors

these work for us without errors

ValentinFunk avatar Oct 07 '20 09:10 ValentinFunk

Hey! Any updates? Thanks a lot!

NashIlli avatar Feb 12 '21 12:02 NashIlli

Same issue when update firebase-functions from 3.3 to 3.13

hungtranpg avatar Mar 11 '21 11:03 hungtranpg

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!

hyst3ric41 avatar Jul 22 '21 04:07 hyst3ric41

Looks like there was incompatibility with old version of the SDK with Node types. If anyone is having similar issue, please open up a new issue instead.

taeold avatar Dec 28 '22 19:12 taeold