简体   繁体   English

构建期间webpack出错但不是dev:“来自UglifyJS的静态错误[...]。 意外的标记:punc(...)“

[英]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.

相关问题 来自 UglifyJs 的 build.js 中的错误意外标记:punc (() - ERROR in build.js from UglifyJs Unexpected token: punc (() Ionic2打字稿设备构建错误&#39;uglifyjs失败:语法错误:意外的令牌运算符«=»,预期的标点«,» - Ionic2 Typescript Device Build Error 'uglifyjs failed: SyntaxError: Unexpected token operator «=», expected punc «,»` 意外的标记 punc «(»,从 UglifyJS 创建块时预期的 punc - Unexpected token punc «(», expected punc when creating chunk from UglifyJS 来自UglifyJs的bundle.js中的webpack错误-ERROR意外的令牌:name(urlParts) - webpack error -ERROR in bundle.js from UglifyJs Unexpected token: name (urlParts) NPM构建失败,带有来自UglifyJs的错误-意外的令牌:名称(上下文) - NPM Build fails w/error from UglifyJs - Unexpected token: name (context) Webpack编译React产生意外的令牌错误 - Unexpected token error from Webpack compiling React npm启动时模块构建失败并出现意外令牌错误-react / webpack - Module Build Failure with Unexpected token error on npm start - react/webpack Webpack + React + Node-错误“意外的令牌导入” - Webpack + React + Node - error “Unexpected token import” Angular 7构建错误-位置0的JSON中的意外令牌 - Angular 7 Build Error - Unexpected token in JSON at position 0 Webpack React 错误:模块解析失败:意外的令牌 - Webpack React error: Module parse failed: Unexpected token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM