1

.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
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
  • Can you try [this](https://stackoverflow.com/questions/48429390/firebase-deploy-errors-starting-with-non-zero-exit-code-space-in-project-path) out. Looks like the same issue. – Tarik Huber May 30 '21 at 21:05

2 Answers2

2

I was in the same situation as you so I leave my quick solution for you. "run lint" while predeploying causes error, Unexpected token => but it's not an error, as we all know.

Solution

  1. After Cleaning out the .eslintrx.js, it will work.

  2. Remove some lines in the firebase.json file.

    in firebase.json file,

    ...
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint"  << DELETE THIS LINE
        ]
      }
  • If you use Windows, \"$RESOURCE_DIR\" should be \"%RESOURCE_DIR%\"
  1. ⭐⭐ Add /* eslint-disable */ on top of the index.jsfile

    (I chose this)

  2. If you want to persist eslint predeploy, play with eslint config file. For example,

  env: {
    es6: true, -> es2017 or higher?? will it work??
    node: true,
  },

See https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments

  1. Find more info in github thread: https://github.com/eslint/eslint/issues/8126
Smith
  • 153
  • 1
  • 2
  • 12
2

1.) Clean .eslintrx.js

2.) in firebase.json file

in firebase.json file, --> delete "npm --prefix "$RESOURCE_DIR" run lint" this line from here

...
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"  
    ]
  }