Webpack/Polyfill Issues with Nodemailer

Hello,

I am a novice in javascript and coding in general so bear with me.

I am trying to use Nodemailer to send emails from my React JS App but get this error.

Module not found: Error: Can't resolve 'stream' in...

and it repeats this error for ‘fs’, ‘path’, ‘crypto’, ‘url’ and many others. It also says…

webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

Then it gives instructions on how to do this:

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

I’m confused though where I should write this fallback code.

Any clarification and help on where exactly I should write this code would be appreciated
Thanks

This doesn’t feel very much like novice territory to me. Tools that are supposed to make life easier, but really make things very complicated.

I found this thread, which seems to be relevant. I think it’s going to involve a bit of trial and error.

Edit: What is the source you are following for this? Is it a course?

Check this topic out https://stackoverflow.com/questions/55601669/module-not-found-error-cant-resolve-stream-in-c-dev-jszip-test-node-modul

Thank you! I will look into this.

Starting to learn JavaScript with, react, Node.js and webpack directly using frameworks like nodemailer….

I wish you luck. You will need it :smiley:

SCNR

As the others have pointed out, there are a lot of moving parts in your project. This makes it difficult for us to know exactly where such an error might be occurring.

If the links posted by Lisa or rpg_digital don’t help you, it would be good if you could make a minimal reproducible example, which demonstrates the problem you are having.

This link explains how:

If you can do that, then your chances of getting some help with your issue will be greatly increased.

1 Like

I was looking for a way to send automated emails and didn’t want to use EmailJS and so nodemailer seemed like the next best option but I would be happy to go in a different direction if someone can point me there.

Thanks. I will try out these ideas once I have some time and update the thread.

So I found some time to work through the solutions. rpg_digital’s didn’t work so I decided to create a new react-app and try nodemailer from the beginning. It still presented the same errors. In Lisa.sun’s link there was the suggestion to switch react-scripts to 4.0.3 in package.json so I did that and it solved the issue. But now I’m thinking this solution will present its own problems if I implement it in my project. My project is a personal website that will have a blog as well as photo album. I’m coding the backend with express as well as the frontend using mysql as the database.

If I switch the react-scripts to 4.0.3, are you able to tell me the consequences this solution will have on my project?

So to bring this thread to a conclusion the problem occurred because I was trying to use nodemailer on the front-end when I should have implemented it on the back-end using express and axios. This video was very helpful for me https://www.youtube.com/watch?v=_3-By9QfFa0&t=619s

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.