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
.
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
.
- Please edit the question to indicate what you upgrade path was. What exactly did you change to produce this error? There should be enough information in your question so that anyone can reproduce the issue. – Doug Stevenson Commented Oct 28, 2020 at 15:22
- Which version of Node? – Guy Incognito Commented Oct 28, 2020 at 15:27
- im still using node 8.. but this is the same as before – Harald Wiesinger Commented Oct 28, 2020 at 15:30
- 5 Firebase libraries require Node 10. Install from legacy-8 for Node 8 support: npmjs.com/package/@google-cloud/… – Guy Incognito Commented Oct 28, 2020 at 15:32
- 3 I got the same error. I downgrade: firebase-admin and firebase-functions to a version I new that worked before: "firebase-admin": "^8.10.0", "firebase-functions": "^3.6.1" and it worked. – Marcel Hoekstra Commented Oct 29, 2020 at 12:01
3 Answers
Reset to default 17Downgrade 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
- Make sure
firebase-functions
is at least version3.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.
You can also get this error if you are running Node.js v8
. Upgrading to Node.js v10
resolves this error.
If you are managing your Node.js version using nvm
, then run:
nvm install v10 --lts
I think it is a better solution than downgrading the firebase-admin
library.