Home > database >  Firebase deploy causing several errors
Firebase deploy causing several errors

Time:11-16

I created Firebase Cloud Functions in VS Code using Typescript and there are no errors shown in VS Code. But when I deploy my firebase code, I get several error messages. Why do I get all these error messages and why does VS Code not show a single one? And how I can fix it such that VS Code shows me the errors?

The Errors:

  8:1   error    More than 2 blank lines not allowed                   no-multiple-empty-lines
   9:1   error    This line has a length of 108. Maximum allowed is 80  max-len
  10:1   error    This line has a length of 120. Maximum allowed is 80  max-len
  19:1   error    This line has a length of 98. Maximum allowed is 80   max-len
  26:1   error    Expected indentation of 4 spaces but found 2          indent
  26:13  error    Strings must use doublequote                          quotes
  27:1   error    Expected indentation of 4 spaces but found 2          indent
  27:20  warning  'context' is defined but never used                   @typescript-eslint/no-unused-vars
  28:1   error    Expected indentation of 6 spaces but found 4          indent
  28:17  error    Strings must use doublequote                          quotes
  28:70  error    Missing semicolon                                     semi
  30:1   error    Expected indentation of 6 spaces but found 4          indent
  30:28  error    Missing semicolon                                     semi
  31:1   error    Expected indentation of 6 spaces but found 4          indent
  31:21  error    Missing semicolon                                     semi
  33:1   error    Expected indentation of 6 spaces but found 4          indent
  33:34  error    Missing semicolon                                     semi
  34:1   error    Expected indentation of 6 spaces but found 4          indent
  34:38  error    Missing semicolon                                     semi
  35:1   error    Expected indentation of 6 spaces but found 4          indent
  35:39  error    Missing semicolon                                     semi
  37:1   error    Expected indentation of 6 spaces but found 4          indent
  38:1   error    Expected indentation of 6 spaces but found 4          indent
  39:1   error    Expected indentation of 10 spaces but found 6         indent
  40:1   error    Expected indentation of 10 spaces but found 6         indent
  40:19  error    Strings must use doublequote                          quotes
  41:1   error    Expected indentation of 10 spaces but found 6         indent
  41:14  error    Strings must use doublequote                          quotes
  41:20  error    Strings must use doublequote                          quotes
  42:1   error    Expected indentation of 10 spaces but found 6         indent
  43:1   error    Expected indentation of 10 spaces but found 6         indent
  43:13  error    Expected parentheses around arrow function argument   arrow-parens
  44:1   error    Expected indentation of 12 spaces but found 8         indent
  44:31  error    Expected parentheses around arrow function argument   arrow-parens
  45:1   error    Expected indentation of 14 spaces but found 10        indent
  45:63  error    Missing semicolon                                     semi
  46:1   error    Expected indentation of 14 spaces but found 10        indent
  47:1   error    Expected indentation of 16 spaces but found 12        indent
  48:1   error    Expected indentation of 16 spaces but found 12        indent
  49:1   error    Expected indentation of 20 spaces but found 14        indent
  50:1   error    Expected indentation of 20 spaces but found 14        indent
  50:27  error    Strings must use doublequote                          quotes
  51:1   error    Expected indentation of 20 spaces but found 14        indent
  51:22  error    Strings must use doublequote                          quotes
  51:28  error    Strings must use doublequote                          quotes
  52:1   error    Expected indentation of 20 spaces but found 14        indent
  53:1   error    Expected indentation of 20 spaces but found 14        indent
  53:21  error    Expected parentheses around arrow function argument   arrow-parens
  54:1   error    Expected indentation of 22 spaces but found 16        indent
  54:40  error    Expected parentheses around arrow function argument   arrow-parens
  55:1   error    Expected indentation of 24 spaces but found 18        indent
  55:74  error    Missing semicolon                                     semi
  56:1   error    Expected indentation of 24 spaces but found 18        indent
  57:1   error    Expected indentation of 26 spaces but found 20        indent
  58:1   error    This line has a length of 81. Maximum allowed is 80   max-len
  58:1   error    Expected indentation of 28 spaces but found 22        indent
  59:1   error    Expected indentation of 28 spaces but found 22        indent
  60:1   error    Expected indentation of 28 spaces but found 22        indent
  60:30  error    Strings must use doublequote                          quotes
  61:1   error    Expected indentation of 28 spaces but found 22        indent
  61:30  error    Strings must use doublequote                          quotes
  61:39  error    Missing trailing comma                                comma-dangle
  62:1   error    Expected indentation of 26 spaces but found 20        indent
  62:22  error    Missing trailing comma                                comma-dangle
  63:1   error    Expected indentation of 24 spaces but found 18        indent
  63:20  error    Missing semicolon                                     semi
  64:1   error    Expected indentation of 24 spaces but found 18        indent
  65:1   error    Expected indentation of 24 spaces but found 18        indent
  66:1   error    Expected indentation of 28 spaces but found 20        indent
  67:1   error    Expected indentation of 28 spaces but found 20        indent
  68:1   error    Expected indentation of 28 spaces but found 20        indent
  68:27  error    Expected parentheses around arrow function argument   arrow-parens
  69:1   error    Expected indentation of 30 spaces but found 22        indent
  69:35  error    Strings must use doublequote                          quotes
  69:74  error    Missing semicolon                                     semi
  70:1   error    Expected indentation of 28 spaces but found 20        indent
  71:1   error    Expected indentation of 28 spaces but found 20        indent
  71:28  error    Expected parentheses around arrow function argument   arrow-parens
  72:1   error    Expected indentation of 30 spaces but found 22        indent
  72:35  error    Strings must use doublequote                          quotes
  72:67  error    Missing semicolon                                     semi
  73:1   error    Expected indentation of 28 spaces but found 20        indent
  73:23  error    Missing semicolon                                     semi
  74:1   error    Expected indentation of 22 spaces but found 16        indent
  74:19  error    Missing semicolon                                     semi
  75:1   error    Expected indentation of 20 spaces but found 14        indent
  75:17  error    Missing semicolon                                     semi
  76:1   error    Expected indentation of 14 spaces but found 10        indent
  77:1   error    Expected indentation of 16 spaces but found 12        indent
  77:25  error    Strings must use doublequote                          quotes
  77:62  error    Missing semicolon                                     semi
  78:1   error    Expected indentation of 14 spaces but found 10        indent
  79:1   error    Expected indentation of 12 spaces but found 8         indent
  79:11  error    Missing semicolon                                     semi
  80:1   error    Expected indentation of 10 spaces but found 6         indent
  80:9   error    Missing semicolon                                     semi
  81:1   error    Expected indentation of 6 spaces but found 4          indent
  81:16  error    Missing semicolon                                     semi
  82:1   error    Expected indentation of 4 spaces but found 2          indent

Cloud Function:

    exports.sendNotification = functions.firestore
  .document('/rooms/{roomId}/messages/{messageId}')
  .onCreate((snap, context) => {
    console.log('----------------start function--------------------')
    const doc = snap.data()
    console.log(doc)

    const senderId = doc.senderId
    const receiverId = doc.receiverId
    const contentMessage = doc.message

    // Get push token user to (receive)
    admin
      .firestore()
      .collection('users')
      .where('id', '==', receiverId)
      .get()
      .then(querySnapshot => {
        querySnapshot.forEach(userTo => {
          console.log(`Found receiver: ${userTo.data().name}`)
          if (userTo.data().token) {
            // Get info user from (sent)
            admin
              .firestore()
              .collection('users')
              .where('id', '==', senderId)
              .get()
              .then(querySnapshot2 => {
                querySnapshot2.forEach(userFrom => {
                  console.log(`Found user from: ${userFrom.data().name}`)
                  const payload = {
                    notification: {
                      title: `You have a message from "${userFrom.data().name}"`,
                      body: contentMessage,
                      badge: '1',
                      sound: 'default'
                    }
                  }
                  // Let push to the target device
                  admin
                    .messaging()
                    .sendToDevice(userTo.data().token, payload)
                    .then(response => {
                      console.log('Successfully sent message:', response)
                    })
                    .catch(error => {
                      console.log('Error sending message:', error)
                    })
                })
              })
          } else {
            console.log('Can not find pushToken target user')
          }
        })
      })
    return null
  });

CodePudding user response:

This occurs when you've enabled the ESLint on Firebase Initialization.

enter image description here

You can run the ESLint directly by heading into your main project folder then execute these commands on your terminal:

cd functions && npx eslint . --fix

or

cd functions && node_modules/eslint/bin/eslint.js . --fix

The above commands will fix what ESLint can fix automatically. If no warnings are caught after running the command, then you can now deploy the function without having an issue. If you have still warnings then you must manually fix it before deploying the function.


Note: If you don't want to use ESLint, you can re-create your project, choose not to use ESLint when it prompts you. Or you can disable it in your current project by editing your firebase.json file and removing the predeploy script that runs the lint command. See sample firebase.json below:

{
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ]
}

Remove these block of code:

"predeploy": [
    "npm --prefix \"$RESOURCE_DIR\" run lint",
    "npm --prefix \"$RESOURCE_DIR\" run build"
]
  • Related