I’m trying to deploy my Firebase Cloud Functions but keep running into an ESLint error during the deployment process. The error says there’s an unexpected token at the arrow function syntax.
My .eslintrc.js configuration:
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
My main function file:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.onMessageCreated = functions.firestore.document("Messages/{messageID}").onCreate((snap, ctx) => {
const messageData = snap.data();
const messageID = ctx.params.messageID;
if (messageData) {
const participants = messageData.participants;
for (let i = 0; i < participants.length; i++) {
const activeUserID = participants[i];
const otherUserIDs = participants.filter((user) => user !== activeUserID);
otherUserIDs.forEach(async (participant) => {
try {
const userDoc = await admin.firestore().collection("Users").doc(participant).get();
const userInfo = userDoc.data();
if (userInfo) {
return admin.firestore().collection("Users").doc(activeUserID).collection("Messages").doc(participant).create({
"messageId": messageID,
"avatar": userInfo.avatar,
"username": userInfo.username,
"unreadCount": 0,
});
}
return null;
} catch (error) {
return null;
}
});
}
}
return null;
});
The deployment error I’m getting:
C:\Users\DEV\Desktop\firebase_project>firebase deploy --only functions
=== Deploying to 'myapp-12345'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint C:\Users\DEV\Desktop\firebase_project\functions
> eslint .
C:\Users\DEV\Desktop\firebase_project\functions\index.js
12:48 error Parsing error: Unexpected token =>
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
Error: functions predeploy error: Command terminated with non-zero exit code1
What could be causing this parsing error and how can I fix it?