I updated my firebase-functions and now I get this error in the Firebase console. The code is still the same, but I get an error now:
/srv/node_modules/@google-cloud/firestore/build/src/collection-group.js:54
async *getPartitions(desiredPartitionCount) {
^
SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/node_modules/@google-cloud/firestore/build/src/index.js:39:28)
This is my cloud function TypeScript source:
import * as functions from 'firebase-functions';
import admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
/********************************************************************/
exports.newChatMessage = functions.firestore
.document('/games/{gameId}/chat/{chatId}')
.onCreate((snap, context) => {
const createData = snap.data();
if(!createData) {
return false;
}
const chatMessage = createData.message;
if(!chatMessage) {
return false;
}
console.log('New Chat message in game: ', context.params.gameId);
const payload = {
notification: {
title: 'New chat message',
body: chatMessage,
icon: 'ic_notification'
}
}
return admin.firestore().collection(`/games/${context.params.gameId}/members`).where( 'notificationChat', '==', true ).get().then( members => {
members.forEach( member => {
if(member.id !== createData.user) {
return admin.firestore().doc(`/users/${member.id}`).get().then( memberdata => {
if( memberdata.get('firebaseToken') === '' ) {
return memberdata.data();
} else {
return admin.messaging().sendToDevice(memberdata.get('firebaseToken'), payload).catch( error => { console.log(error) });
}
}).catch( error => { console.log(error) });
} else {
return false;
}
})
}).catch( error => { console.log(error) });
});
What is this? In my functions there isn't any method named *getPartitions
.
You can either catch FirebaseError in your code and check its code , or perform an isinstance() check against a platform error class. Or you can write code to directly catch specific platform error types. The latter approach is likely to result in more readable error handling code.
Downgrade firebase-admin and firebase-functions to version: "firebase-admin": "^8.10.0", "firebase-functions": "^3.6.1" and it will work.
Thanks to Marcel Hoekstra for posting this in the comments.
As Uzbekjon stated, you can get this error if running node v8
instead of v10
. Some comments mentioned this was not the desired solution, because they didn't want to upgrade to Firebase's Blaze plan. Unfortunately, there's not going to be much of a choice in the matter soon.
If you go to your Firebase Functions in the console, you'll notice a warning that "Node V8 has been deprecated". As of Feb 15 2021 you will no longer be able to make changes to or deploy any functions using Node.js V8. As of March 15, 2021 you will no longer be able to use the functions at all. They will be completely blocked from execution.
Blog post Migrate your Firebase Cloud Functions to Node.js 10 was really good for explaining how to upgrade to v10
. I follow the author's steps and redeployed - no error and no deprecation warning.
Required Updates
Check to make sure you have at least Node.js V10 installed globally on your machine node --version
.
npm install -g firebase-tools@latest
(you need at least version 8.1.0)
In your package.json file, make sure Node.js V10 is targeted like this:
"engines": {
"node": "10"
}
Check your Firebase environment variables. The source I linked to goes into further detail and links other explanation sources, but basically upgrading might mean default environment variable names have changed (I didn't have to change anything here).
Recommended
firebase-functions
is at least version 3.7.0
. I had to update this anyway to solve another error.Optional, but still recommended
Update your compiler options in tsconfig.json
. This will make it so unnecessary language versions are not transpiled.
"compilerOptions": {
"target": "es2018",
"lib": ["es2018"],
}
Test your code :)
Like I mentioned earlier, making this upgrade removed the error for me. Once I made a new deployment, all deprecation warnings were also removed from the Firebase Functions console.
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