[英]Webpack's UglifyJsPlugin throws error with Node modules containing let
This is the relevant code (I'm using Vue.js' Webpack official template): 这是相关的代码(我正在使用Vue.js的Webpack官方模板):
.babelrc: .babelrc:
"presets": [
"babel-preset-es2015",
"babel-preset-stage-2",
]
webpack.prod.config.js webpack.prod.config.js
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: shouldDropConsole
},
sourceMap: true
}),
This is the error I get when I do npm run build
: 这是我执行
npm run build
时遇到的错误:
ERROR in static/js/vendor.a6271913414e87e123c2.js from UglifyJs Unexpected token: name (_months) [./node_modules/calendar-js/index.js:56,0][static/js/vendor.a6271913414e87e123c2.js:90602,6]
来自UglifyJs的static / js / vendor.a6271913414e87e123c2.js中的错误意外令牌:名称(_months)[./node_modules/calendar-js/index.js:56,0][static/js/vendor.a6271913414e87e123c2.js:90602, 6]
This is the offending line: 这是违规行:
let _months = MONTHS;
(If I replace all the let
's to var
s the project is built without problems. And the const
's don't seem to bother Webpack/UglifyJS.) (如果我将所有的
let
替换为var
那么项目构建就没有问题。而且const
似乎不会打扰Webpack / UglifyJS。)
Do I need to configure something so that Webpack/UglifyJS build node modules containing let
's? 我是否需要配置一些东西,以便Webpack / UglifyJS构建包含
let
的节点模块? (The let
's in my actual project don't give me problems.) (在我的实际项目中,
let
没有遇到任何问题。)
This could be because you might be using an older version of node
which does not support es6 syntax. 这可能是因为您使用的
node
版本可能不支持es6语法。
let
, const
, arrow functions etc. are part of es6 syntax. let
, const
,arrow函数等是es6语法的一部分。 To know more follow this link http://es6-features.org/ 要了解更多信息,请点击此链接http://es6-features.org/
You might need the older version of node
for your other projects so install nvm. 您的其他项目可能需要较旧版本的
node
,因此请安装nvm。 NVM is a node version manager which will help you to switch between node versions easily. NVM是节点版本管理器,它将帮助您轻松地在节点版本之间切换。 Follow the link for documentation and installation process https://github.com/creationix/nvm
遵循文档和安装过程的链接https://github.com/creationix/nvm
Node v6+ supports ES6 syntax try upgrading to that. Node v6 +支持ES6语法,请尝试将其升级。
UPDATE UPDATE
On the comments of this answer, it's confirmed that it was not a version issue and got resolved by following this GitHub issue thread https://github.com/joeeames/WebpackFundamentalsCourse/issues/3 . 关于此答案的评论,已确认这不是版本问题,并通过遵循此GitHub问题线程https://github.com/joeeames/WebpackFundamentalsCourse/issues/3得以解决。
Peace! 和平!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.