firebase-functions
firebase-functions copied to clipboard
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.
abra o caminho: functions>src no terminal de comando e faรงa um npm install --save express
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.
Same issue with firebase-functions 3.6.0.
Likewise since updating to the latest version of firebase-functions. I was previously on 3.3.0.
I am also experiencing the same issue after upgrading firebase-functions from 3.3.0 to 3.6.1
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.
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?
Same issue with firebase-functions 3.7.0
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.
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
this export const api = functions.https.onRequest(
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 Could you try doing a ls-command to check which version of the express types you are running?
npm ls "@types/express"
functions@ /Users/..../workspace/sinvoicescloud/functions โโโฌ @types/[email protected] โ โโโ @types/[email protected] โโโฌ [email protected] โโโ @types/[email protected]
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 Great to hear! What does the ls command say now?
@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 Yes, I think that is likely. Thanks!
Any update?
Any updates to this?
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
Hey! Any updates? Thanks a lot!
Same issue when update firebase-functions
from 3.3 to 3.13
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!
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.