Using the "child_process" module without Webpack

I use Webpack to bind dependencies, one of which is the email service postmark. This service depends on what is called child_process, which apparently comes with node.

The problem is that when I try to start webpack to bundle my application, it complains:

Module not found: Error: cannot resolve module "child_process" to ...

Most of the answers on the Internet say that in response to this error I should add the line:

  node: {
    child_process: 'empty'
  }

into my webpack configuration. But this does not make any sense, because then webpack just does not try to look for child_process, and therefore, when I launch my application, I get the following error:

Uncaught TypeError: exec is not a function

which is a bug postmark(a service that relies on child_process) complains that the function execin the module child_processdoes not exist.

So I am wondering how can I include a module child_processin my assembly without complaining about the web package?

+4
source share
1 answer

The developer of the Postmark interface is here.

It sounds like you're trying to link postmark.jswith your client-side JavaScript, but https://github.com/wildbit/postmark.js is Node. js library. This means that it will not start in the browser and requires the Node.js server to start.

The main reason for the lack of browser support is security. As you can see in this example:

var postmark = require("postmark");
var client = new postmark.Client("<server key>");

auth. JS API.

, .

+2

Source: https://habr.com/ru/post/1625760/


All Articles