[英]Error in webpack during build but not dev: “ERROR in static[…] from UglifyJS. Unexpected token: punc (…)”
Came across this error after adding a module (in my case it's vue2-dropzone
but apparently this occurs with some other node modules as well) to my codebase. 在我的代码库中添加一个模块(在我的情况下是vue2-dropzone
但显然这也出现在其他一些节点模块中)之后遇到了这个错误。 It occurred when I ran npm run build
, but everything worked fine using the webpack dev server ( npm run dev
). 它发生在我运行npm run build
,但是使用webpack dev服务器( npm run dev
)一切正常。
ERROR in static/js/vendor.5efd79c0d4a823d6add3.js from UglifyJs
Unexpected token: punc (() [./node_modules/vue2-dropzone/dist/vue2Dropzone.js:1,41920][static/js/vendor.5efd79c0d4a823d6add3.js:42174,41885]
Found a simple solution to the problem, which I'm posting as an answer below -- but would very much like to hear if anyone knows WHY this fixes the problem. 找到了一个简单的问题解决方案,我将其作为下面的答案发布 - 但非常想听听是否有人知道为什么这可以解决问题。
The issue is that for reasons above my pay grade, babel-loader
must be used to load this particular module. 问题是,由于我的工资等级以上的原因,必须使用babel-loader
来加载这个特定的模块。 Or something like that. 或类似的东西。 The solution is to modify your webpack.base.conf.js
file to include the offending module (whichever one appears in the error above) in the babel-loader rule as follows: 解决方案是修改webpack.base.conf.js
文件,以在babel-loader规则中包含违规模块(上面的错误中出现的任何一个),如下所示:
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/<NAME_OF_NODE_MODULE>')]
}
UPDATE (per SLaks in the comments): This happens when UglifyJS requires Babel's features (eg language extensions) in order to understand a given module's code. 更新 (评论中的每个SLaks ):当UglifyJS需要Babel的功能(例如语言扩展)以理解给定模块的代码时,就会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.