I tried to update the dependencies of my Firebase functions project to use more recent versions of firebase-functions and firebase-admin, which in turn seemed to required more recent versions of TypeScript and tslint. Here is my resulting package.json:
{
"name": "functions",
"scripts": {
"lint": "./node_modules/.bin/tslint -p tslint.json",
"build": "./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"engines": {
"node": "8"
},
"dependencies": {
"@types/jsonwebtoken": "^7.2.8",
"axios": "^0.18.1",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.1.0",
"handlebars": "^4.1.2",
"html-pdf": "^2.2.0",
"js-sha256": "^0.9.0",
"json2csv": "^4.1.2",
"jsonwebtoken": "^8.3.0",
"jwks-rsa": "^1.3.0",
"moment": "^2.24.0",
"pdfkit": "^0.9.1",
"uuid": "^3.3.2",
"validator": "^10.11.0"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}
But now with that, when I try to deploy my Firebase functions, I get a bunch of Typescript compilation errors I can't even understand. Anybody has any idea what those are and how to fix them or work around them?
Running command: npm --prefix $RESOURCE_DIR run build
> functions@ build /Users/sarbogast/dev/myproject/backend/functions
> tsc
node_modules/@google-cloud/storage/build/src/file.d.ts:35:29 - error TS2694: Namespace '"http"' has no exported member 'OutgoingHttpHeaders'.
35 extensionHeaders?: http.OutgoingHttpHeaders;
~~~~~~~~~~~~~~~~~~~
node_modules/@types/node/index.d.ts:54:11 - error TS2300: Duplicate identifier 'IteratorResult'.
54 interface IteratorResult<T> {}
~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'.
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
node_modules/@types/node/index.d.ts:54:11
54 interface IteratorResult<T> {}
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
Found 3 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/sarbogast/.npm/_logs/2019-09-03T14_57_53_748Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
I was able to fix this by adding "typeRoots": ["node_modules/@types"] to compilerOptions in the tsconfig.json.
I found this solution here
So here is how I managed to solve the issue: I installed @types/node as an explicit dev dependency and it was enough. Here is what my package.json ended up looking like:
{
"name": "functions",
"scripts": {
"lint": "./node_modules/.bin/tslint -p tslint.json",
"build": "./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"@types/jsonwebtoken": "^7.2.8",
"axios": "^0.18.1",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.2.0",
"handlebars": "^4.1.2",
"html-pdf": "^2.2.0",
"js-sha256": "^0.9.0",
"json2csv": "^4.1.2",
"jsonwebtoken": "^8.3.0",
"jwks-rsa": "^1.3.0",
"moment": "^2.24.0",
"pdfkit": "^0.9.1",
"uuid": "^3.3.2",
"validator": "^10.11.0"
},
"devDependencies": {
"@types/node": "^12.7.5",
"tslint": "~5.8.0",
"typescript": "^3.6.3"
},
"private": true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With