使用模块“child_process”没有Webpack [英] Using module "child_process" without Webpack

查看:351
本文介绍了使用模块“child_process”没有Webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Webpack捆绑依赖项,其中一个是电子邮件服务邮戳。这项服务取决于显然附带节点的名为 child_process 的东西。

I'm using Webpack to bundle dependencies, one of which is the emailing service postmark. This service depends upon something called child_process that apparently ships with node.

问题是,当我试图运行时webpack捆绑我的应用程序,它抱怨:

The problem is, when I attempt to run webpack to bundle my app, it complains:


找不到模块:错误:无法解析模块'child_process'...

Module not found: Error: Cannot resolve module 'child_process' in ...

网上的大多数答案都说,为了回应这个错误,我应该添加一行:

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

  node: {
    child_process: 'empty'
  }

到我的webpack配置。但这没有任何意义,因为然后webpack不会尝试寻找child_process,因此,当我运行我的应用程序时,我收到以下错误:

to my webpack config. But this makes no sense, because then webpack just doesn't try to look for child_process, and consequently, when I run my app, I get the following error:


未捕获的TypeError:exec不是函数

Uncaught TypeError: exec is not a function

这是来自邮戳的错误(依赖于 child_process 的服务)抱怨<$ c中的 exec 函数$ c> child_process 模块不存在。

which is an error from postmark (the service that relies upon child_process) complaining that the exec function within the child_process module doesn't exist.

因此,我想知道如何包含 child_process 我的构建中没有webpack抱怨的模块?

Thus, I'm wondering how I can include the child_process module in my build without webpack complaining?

推荐答案

邮戳的前端开发人员在这里。

Front-end developer of Postmark here.

看起来你正试图将 postmark.js 捆绑到你的客户端JavaScript中,但 https://github.com/wildbit/postmark.js 是一个Node.js库。这意味着它不会在浏览器中运行并且需要运行Node.js服务器。

It looks like you're trying to bundle postmark.js into your client-side JavaScript but https://github.com/wildbit/postmark.js is a Node.js library. This means it will not run in the browser and requires a running Node.js server.

不支持浏览器环境的主要原因是安全性。正如您在此示例中所见:

The main reason for not supporting browser environment is security. As you can see in this example:

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

它要求您插入身份验证令牌。将此与您的客户端JS捆绑在一起会暴露它并允许每个人访问您的邮戳帐户API。

it requires you to insert the auth token. Bundling this with your client-side JS would expose it and allow everyone access your postmark account API.

希望这可以澄清它。

这篇关于使用模块“child_process”没有Webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆