.eslintrx.js
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
index.js
let functions = require('firebase-functions');
let admin = require('firebase-admin');
admin.initializeApp();
exports.onConversationCreated;
onConversationCreated = functions.firestore.document("Conversations/chatID").onCreate((snapshot, context) => {
let data = snapshot.data();
let chatID = context.params.chatID;
if (data) {
let members = data.members;
for (let index = 0; index < members.length; index++) {
let currentUserID = members[index];
let remainingUserIDs = members.filter((u= string) => u !== currentUserID);
remainingUserIDs.forEach(async (m= string) => {
try {
let _doc = await admin.firestore().collection("Users").doc(m).get();
let userData = _doc.data();
if (userData) {
return admin.firestore().collection("Users").doc(currentUserID).collection("Conversations").doc(m).create({
"chatId": chatID,
"image": userData.image,
"name": userData.name,
"unseenCount": 0,
});
}
return null;
} catch (e) {
return null;
}
});
}
} return null;
});
Error I getting:
C:\Users\TOHID\Desktop\chat_firebase_function>firebase deploy --only functions
=== Deploying to 'chatapp-1b389'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint C:\Users\TOHID\Desktop\chat_firebase_function\functions
> eslint .
C:\Users\TOHID\Desktop\chat_firebase_function\functions\index.js
15:52 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`enter code here`
npm ERR!
npm ERR! Failed at the functions@ lint 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! C:\Users\TOHID\AppData\Roaming\npm-cache\_logs\2021-05-30T16_54_32_266Z-debug.log
events.js:353
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26) at verifyENOENT (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16) at ChildProcess.cp.emit (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\TOHID\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
path: 'npm --prefix "%RESOURCE_DIR%" run lint',
spawnargs: []
}
Error: functions predeploy error: Command terminated with non-zero exit code1
Having trouble? Try firebase [command] --help