Is it true webpack5 is unable to polyfill libraries? What are some solutions?

Tags: , , ,



My problem was: I was using require in a js script used in the browser (to download nodemailer). Following the advice of this SO post, I downloaded browserify. It allowed me to use require in a js file used by the browser.

Webpack was another alternative listed. It is more common than browserify & has more features (like intelligently arranging files that import & export (from one another)).

However, it looks like webpack doesn’t work with nodemailer. Here is my error code when I try to make my bundle.js file:

enter image description here

My question is:

  • Is my summation of my problems, and my steps to solve them, reasonable?
  • If so, what are some common solutions people’re using? For instance: I like webpack & would like to use libraries in `js` scripts. Are people using both?

Answer

Webpack has no problems handling require, that is its raison d’ĂȘtre!

You can’t polyfill Nodemailer. It depends on APIs that Node.js supplies but which are not available in web browsers.

If you want to send email from a web browser then the usual approach is to make an HTTP request to a web service which sends the email.



Source: stackoverflow