firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[messaging] http module : failed to execute source

Open Tom3652 opened this issue 3 years ago • 0 comments

[READ] Step 1: Are you in the right place?

  • For issues related to the code in this repository file a Github issue.
  • If the issue pertains to Cloud Firestore, read the instructions in the "Firestore issue" template.
  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MongoDB Atlas Trigger (Realm App)
  • Firebase SDK version: 11.0.1
  • Firebase Product: messaging
  • JS SDK Version: 3.18.0
  • NPM version: I don't know

[REQUIRED] Step 3: Describe the problem

Executing admin.messaging().sendMulticast(message) returns an error but is actually working :

FunctionError: 'http' module: FunctionError: failed to execute source for 'node_modules/@fastify/busboy/lib/main.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js': FunctionError: failed to execute source for 'node_modules/@fastify/busboy/lib/utils.js': TypeError: Value is not an object: undefined
    at node_modules/@fastify/busboy/lib/utils.js:23:27(322)

    at require (native)
    at node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:15:24(29)

    at require (native)
    at node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:19:28(39)

    at require (native)
    at node_modules/@fastify/busboy/lib/main.js:28:21(44)

    at execute (native)
    at <eval>:16:29(8)
    at K (<eval>:10:6625(35))
    at <eval>:10:4454(115)
    at M (<eval>:10:9199(23))
    at T (<eval>:10:9026(174))
    at <eval>:10:9810(49)
    at onStreamRead (<eval>:10:2062(36))

My Atlas Trigger reports error anyway even if the code is successfully executed.

Here is my StackOverflow bounty on the subject but since no one has an obvious answer i have decided to raise an issue here.

Steps to reproduce:

  1. Create a MongoDB Atlas trigger
  2. Add firebase-admin as external dependency
  3. Add the service-account.json as a value
  4. Run the code with the below code

Relevant Code:

exports = async function() {

  const admin = require("firebase-admin");
  const json_creds = context.values.get("service_account_value_name");
  	  
    const title = "Test";
    const body = "This is a test";
   
    const message= {
      android: {
        notification: {
          title: title,
          sound: "default",
          body: body,
        },
      },
      apns: {
        payload: {
          aps: {
            alert: {
              title: title,
              body: body,
            },
            mutableContent: 1,
            contentAvailable: 1
          }
        },
      },
      tokens: ["device_token_1", "device_token_2"]
    };
    	
    admin.initializeApp({
        credential: admin.credential.cert(JSON.parse(json_creds))
      });
  
    admin.messaging().sendMulticast(message);

    console.log("Messages sent !");
  }
}

Tom3652 avatar Sep 16 '22 11:09 Tom3652