Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: source.on is not a function at Function.DelayedStream.create #383

Closed
maurocolella opened this issue Aug 21, 2023 · 5 comments · Fixed by #405
Closed

TypeError: source.on is not a function at Function.DelayedStream.create #383

maurocolella opened this issue Aug 21, 2023 · 5 comments · Fixed by #405

Comments

@maurocolella
Copy link

maurocolella commented Aug 21, 2023

Hi,

I am using:

    "mailgun.js": "^9.2.0",
    "form-data": "^4.0.0",
    "typescript": "^3.9.2",

First, the documentation doesn't seem to indicate the correct/latest api to work with form-data, so instead of:

import * as FormData from 'form-data'
const mailgun = new Mailgun(FormData)

I have to use:

import FormData from 'form-data'
const mailgun = new Mailgun(FormData)

Minor issue.

Then, when trying to construct a file to upload, I use:

        payload.attachment = {
          data: fileData,
          filename: metadata.name,
        }

fileData here is either a node Buffer, or a readableStream as made available to me by a third-party library.

On paper, either of these things should work, but neither does.

I get:

TypeError: source.on is not a function 
at Function.DelayedStream.create (/app/node_modules/delayed-stream/lib/delayed_stream.js:33:10) 
at FormData.CombinedStream.append (/app/node_modules/combined-stream/lib/combined_stream.js:45:37) 
at FormData.append (/app/node_modules/form-data/lib/form_data.js:75:3) 
at e.addCommonPropertyToFD (/app/node_modules/mailgun.js/mailgun.node.js:2:65203)
at /app/node_modules/mailgun.js/mailgun.node.js:2:64130
at Array.reduce (<anonymous>)
at e.createFormData (/app/node_modules/mailgun.js/mailgun.node.js:2:63963)
at e.postWithFD (/app/node_modules/mailgun.js/mailgun.node.js:2:73194)
at e.create (/app/node_modules/mailgun.js/mailgun.node.js:2:42518)

Now, I realize that this might be an issue with form-data rather than mailgun.js, but since it is a recommended dependency, I thought I might raise it here. I have tried alternative form data libraries, to no avail.

Please advise.

@joaopedrocoelho
Copy link

I'm having the same problem trying to use mailgun.js in a strapi project

@olexandr-mazepa
Copy link
Collaborator

olexandr-mazepa commented Sep 14, 2023

Hi @maurocolella
I've checked fs.ReadStream as value for attachment.data and it works well.
Also based on the error stack above the issue may be with the another property in payload.

As you may see addCommonPropertyToFD was used.
It basically means that this block of code
https://github.com/mailgun/mailgun.js/blob/970c9b66e067cb39d307b2b771bc7ae6f2a5fd2b/lib/Classes/common/FormDataBuilder.ts#L17C63-L30
either didn't recognise the payload key as "attachment" or issue is with another property.

Let me know if I can help you somehow and it would be nice to see whole payload object of cource with hidden/replaced values.

@maurocolella
Copy link
Author

Hi @olexandr-mazepa . Thank you for your reply! I am handing over my work on this project, so I expect someone will pick this up to look into a solution. We do retrieve our streams from a cloud bucket and SDK (Google Cloud), so there might be something to clarify about that.

@thongle12
Copy link

Same as me, Is anyone has the solution yet?

@olexandr-mazepa
Copy link
Collaborator

Hi @thongle12 @joaopedrocoelho
I wasn't able to reproduce the issue, unfortunately.
It would be awesome if you could provide a minimal reproducible example to speed up the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants