firebase-functions: Build failed with error TS2416 in firebase-functions/lib/common/providers/database.d.ts(80,5)
Related issues
[REQUIRED] Version info
node:18.12.1
firebase-functions:4.4.0
firebase-tools:12.4.4
firebase-admin:11.9.0
[REQUIRED] Test case
Deploy any firestore trigger functions
[REQUIRED] Steps to reproduce
I am trying to deploy a function that I have updated a hundred times before. I didn’t make any code changes or library changes and also successfully deployed the same function yesterday. I started facing this issue.
I also tried the latest function and admin libraries in another project and tried deploying the same function; I still get the same error. Also tried deploying a different function entirely and still get the same error. An important note is that I haven’t changed any code; it was working fine till yesterday.
The function I am deploying is a simple onUpdate trigger.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
import { getFirestore, Timestamp } from 'firebase-admin/firestore'
import { firestoreRegion } from './config';
import { PromoCode } from './types';
import { adminFetch } from './utils';
import { getAuth } from 'firebase-admin/auth';
admin.initializeApp()
const db = getFirestore()
exports.addPromoPurchaseToUser = functions.region(firestoreRegion)
.firestore
.document('promoCodes/{promoCodeId}')
.onUpdate(async (change, context)=>{
const defaultDurationSeconds = 2678400 //set default duration to a month
const yearDurationSeconds = 365 * 24 * 60 * 60
const previousData = change.before.exists ? change.before.data() as PromoCode : undefined
const promoCode = change.after.exists ? change.after.data() as PromoCode : undefined
if(!promoCode){
//code doesn't exist; do nothing
return
}
const durationSeconds = promoCode?.durationSeconds ? promoCode.durationSeconds : promoCode?.duration ? promoCode.duration * 24 * 60 * 60 : defaultDurationSeconds
//only use user id if different from previous id
const userId = previousData?.user !== promoCode.user ? promoCode.user : undefined
if (!userId){
//we can consider adding delete function here in case we want to allow deleting user on a code
console.log(`Promo code ${context.params.promoCodeId} updated but userId unchanged or not set`)
return
}
const purchaseDate = Timestamp.now()
const expirationDate = new Timestamp(purchaseDate.seconds + (durationSeconds === -1 ? yearDurationSeconds : durationSeconds), 0)
console.log(`Adding promo code (${context.params.promoCodeId}) purchase to ${userId}`)
const purchaseDoc = await db.collection(`users/${userId}/purchases`).add({
purchaseDate: purchaseDate,
expirationDate: expirationDate,
durationSeconds: durationSeconds,
promoCode: context.params.promoCodeId,
//set grants if set in code
...(promoCode.grants ? { grants: promoCode.grants } : {}),
})
//fetch user data to set name and provider ids
const userRecord = await adminFetch("Fetching user data", () => {
return getAuth().getUser(userId)
})
const providerIds = userRecord?.providerData?.map(provider => provider?.providerId) ?? []
//if we have an order reference update the status of this code in the order; more fields can be added later; do with dot ref to not modify existing
if (promoCode.purchaseInfo?.orderReference) {
console.log(`Order reference existed: update promo code status for ${promoCode.purchaseInfo.orderReference.id}`)
try {
await promoCode.purchaseInfo.orderReference.update({
[`promoCodeInfo.${context.params.promoCodeId}`]: {
claimed: true,
user: userId,
userProviderIds: providerIds,
},
})
} catch (e) {
console.log(`error occurred while trying to update promo code status for order ref: ${promoCode.purchaseInfo.orderReference.path}`)
}
}
return change.after.ref.update({
userName: userRecord?.displayName ?? "",
claimedAt: purchaseDate,
userProviderIds: providerIds,
purchaseReference: purchaseDoc,
})
})
My package.json is as follows:
{
"name": "functions",
"scripts": {
"lint": "eslint \"src/**/*\"",
"build": "tsc",
"emulate": "firebase emulators:start",
"serve": "yarn build && firebase emulators:start --only functions",
"shell": "yarn build && firebase functions:shell",
"start": "yarn shell",
"deploy:test-promo": "firebase use test-promo && yarn run deployOnlyPromo",
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"eslint": "^8.29.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.26.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.9.4"
},
"private": true
}
[REQUIRED] Expected behavior
The function should have deployed successfully.
[REQUIRED] Actual behavior
i functions: updating Node.js 16 function addPromoPurchaseToUser(europe-west2)...
Build failed: > build
> tsc
node_modules/firebase-functions/lib/common/providers/database.d.ts(80,5): error TS2416: Property 'child' in type 'DataSnapshot' is not assignable to the same property in base type 'DataSnapshot'.
Type '(childPath: string) => DataSnapshot' is not assignable to type '(path: string) => DataSnapshot'.
Call signature return types 'DataSnapshot' and 'DataSnapshot' are incompatible.
The types of 'forEach' are incompatible between these types.
Type '(action: (a: DataSnapshot) => boolean | void) => boolean' is not assignable to type '(action: (a: IteratedDataSnapshot) => boolean | void) => boolean'.
Types of parameters 'action' and 'action' are incompatible.
Types of parameters 'a' and 'a' are incompatible.
Type 'DataSnapshot' is not assignable to type 'IteratedDataSnapshot'.
Types of property 'key' are incompatible.
Type 'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'.
node_modules/firebase-functions/lib/common/providers/database.d.ts(100,5): error TS2416: Property 'forEach' in type 'DataSnapshot' is not assignable to the same property in base type 'DataSnapshot'.
Type '(action: (a: DataSnapshot) => boolean | void) => boolean' is not assignable to type '(action: (a: IteratedDataSnapshot) => boolean | void) => boolean'.; Error ID: 1a2262f3
Functions deploy had errors with the following functions:
addPromoPurchaseToUser(europe-west2)
Were you able to successfully deploy your functions?
Nope as indicated above.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 30 (1 by maintainers)
I’m still getting this issue with version 12.0.0 of firebase-admin. 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”, “run-emulators”: “firebase emulators:start --import=…/emulators-data --export-on-exit” }, “engines”: { “node”: “16” }, “main”: “lib/index.js”, “dependencies”: { “firebase-admin”: “12.0.0”, “firebase-functions”: “^4.4.1”, }, “devDependencies”: { “@typescript-eslint/eslint-plugin”: “^6.7.0”, “@typescript-eslint/parser”: “^6.7.0”, “eslint”: “^8.26.0”, “eslint-config-google”: “^0.14.0”, “eslint-plugin-import”: “^2.26.0”, “firebase-functions-test”: “^3.0.0”, “typescript”: “5.3.3” }, “private”: true }
+1, facing this again in Jan 2024.
Maybe it should’ve never been closed, arbitrarily downgrading dependencies is not an actual solution…
Same here. Shouldn’t this be reopened?
Same issue still persists with
firebase-admin: ^12.0.0
andfirebase-functions: ^4.6.0
. Commenting to get visibility for this issue.Same issue with firebase-admin: ^12.0.0, firebase-functions: ^4.6.0
Filed a new issue for this to get triaged: https://github.com/firebase/firebase-functions/issues/1515
Hi all, thanks for escalating this issue. We’ve released an emergency patch for
firebase-admin
(11.10.1
) that addresses the regression. See https://firebase.google.com/support/release-notes/admin/node#version_11101_-_13_july_2023 for more details.+1
Hi there!
Thanks a lot for the responses. I was able to deploy after changing
"firebase-admin": "^11.9.0"
to"firebase-admin": "11.9.0"
.Usually, I always try staying on the latest versions but I’ll stick to this version till the issue is fixed in the latest firebase-admin.
Appears to be issue with new firebase-admin version firebase-admin 11.10.0 https://www.npmjs.com/package/firebase-admin/v/11.10.0
Downgrade to 11.9.0 and you should fix the issue.
If you downgrade firebase-admin though, you lose the firestore aggregate query features 😦
I have the same problem. Downgrading to firebase-admin: ^11.10.1, firebase-functions: ^4.6.0 fixes it
I had the same issue, and it turned out to be caused by upgrading
@firebase/rules-unit-testing
to version 3.0.0. Downgrading to version 2.0.7 resolved the issue.I suspect this is related to the update of firebase-js-sdk to version 10.0.0:~~https://github.com/firebase/firebase-js-sdk/blob/master/packages/firebase/CHANGELOG.md#1000~~It seems that this issue occurs when depending on version 1.0.0 of
@firebase/database-compat
.@faizanabidnaqvi I think in your case, fixing the version of firebase-admin should resolve the issue.
+1 Same issue, i’m using this workaround
Other packages i’m using:
Typescript version:
Well you can’t get around breaking changes some times, altough you are right, there are more (unnecessary) breaking changes! However personally I don’t really mind as long as the dependencies reflect that and there is any compatible version 😄
Understandable, have a nice day 😂
Is there any way to get this issue reopened or escalated? @blidd-google (You closed this issue the last time)
I don’t really agree with you on this, I think it’s fairly common to have incompatible packages like this, however these incompatibilties do need to be reflected in their dependencies!
For me the real problem here is that the recommended and latest versions of these packages are not comaptible, espacially since package constraints don’t seem to reflect this (and this could have easily be caught by a unit test)!
Thereby making it impossible to use some of the new features, since (as far as I managed to test) the latest version of
firebase-functions
seems to not be compatible with anyfirebase-admin
version 😓I also have faced this issue with firebase-admin 12.0.0 and firebase-functions 4.6.0. Downgrade to firebase-admin 11.11.1 worked for me.
Same issue with firebase-admin: ^12.0.0, and I have found a temporary solution to this problem.
https://github.com/firebase/firebase-functions/issues/1496#issuecomment-1890918251
I’m also seeing this compatibility issue between
firebase-admin: 12.0.0
andfirebase-functions: 4.5.0
. It seem you need to either downgradefirebase-admin
orfirebase-functions
a major version to get this to work with the current releases:firebase-admin: ^12.0.0
,firebase-functions: ^3.24.1
firebase-admin: ^11.10.1
,firebase-functions: ^4.5.0
I’m seeing the same issue with
firebase-admin: ^12.0.0
andfirebase-functions: ^4.5.0
@blidd-google Can this issue be reopened, I did not find an open issue about this?
@azaandam for now I downgraded to these versions