Webpack 在包输出中导致语法错误 [英] Webpack causes syntax error in bundle output
问题描述
我一直在为一个我认为是由 Webpack 引起的问题而苦苦挣扎.
I've been struggling for a while now with a problem that I believe is caused by Webpack.
本质上,我有一个基于 Node 的应用程序,我将它与 Webpack 捆绑在一起为客户端提供服务(它是一个基于 ReactJS 的应用程序).当我安装 Tabletop NPM 包并require
d 它时出现问题.
Essentially, I have a Node-based app that I'm bundling up with Webpack to serve to the client (it's a ReactJS based app). The problem occured when I installed the Tabletop NPM package and require
d it.
尝试在浏览器中加载 Webpack 创建的 bundle.js
时,出现语法错误:
When attempting to load the Webpack-created bundle.js
in the browser, I get a syntax error:
Uncaught SyntaxError: Unexpected identifier
抱怨 bundle.js
中的这一行:
<代码>target[capName] = __webpack_require__(387)(""path + '/' + name);
经过一番挖掘,我发现这条线源自 Hoek 库(这是Tabletop 的一个子依赖项):
After some digging, I discover that this line originates from a line in the Hoek library (which is a sub-dependency of Tabletop):
<代码>target[capName] = require(path + '/' + name);
显然,Webpack 在这里做了一些时髦的事情.
Clearly, Webpack has done something funky here.
我一直无法找出原因.Tabletop 包括 一个示例 NodeJS 用法,我可以使用它进行 Webpack 和运行就好了.
I haven't been able to isolate the cause though. Tabletop includes an example of NodeJS usage which I was able to Webpack and run just fine.
我还克隆了 Hoek 和 Webpacke,没有看到任何像上面这样的非法转换.
I also cloned Hoek and Webpacke'd it without seeing any illegal transformations like the above.
所以现在,我不确定这是 Webpack、Hoek 还是 Tabletop 问题,这就是我在这里发布的原因.
So now, I'm not sure if this is a Webpack, Hoek, or Tabletop issue, that's why I'm posting it here.
我在此处或 GH 上均未发现相关问题.
I find no related issues, here or on GH.
感谢所有帮助!
推荐答案
由于上面显示的动态 require 行,结果是 hoek
包的过时嵌套依赖项导致了此问题.这已在 hoek@2.0.0 中删除.
Turns out an outdated nested dependency of the hoek
package caused this, due to the dynamic require line shown above. This was removed in hoek@2.0.0.
不幸的是,Tabletop 的 request
dep 有一个过时的 hawk
依赖项,它再次依赖于 hoek
.我分叉了 request
并修改了版本,但现在我在浏览器中加载时遇到了不同的错误:
Unfortunately, Tabletop's request
dep has an outdated dependency of hawk
which again depends on hoek
. I forked request
and bumped the version, but now I am getting a different error on load in the browser:
<代码>未捕获的错误:找不到模块net"
net
是一个核心的 Node 模块,所以我怀疑这里发生了一些事情,因为我们正在 Webpacking 服务器端 JS 以在浏览器中运行它.尽管如此,这是一个不同的问题,所以我认为这里的原始问题已得到解答..
net
is a core Node module, so I suspect there is something going on here since we're Webpacking serverside JS to run it in the browser. Nevertheless, that is a different issue so I consider the original question here answered..
但我仍然无法使用桌面.我可能需要对其进行浏览器化并直接使用该包.
But I'm still unable to use Tabletop. I might have to Browserify it and use that bundle directly.
这篇关于Webpack 在包输出中导致语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!