Reputation: 131
I used webpack2 to build my app, but when use uglify-js + uglifyjs-webpack-plugin.I have some problems:
ERROR in vendors.js from UglifyJs
TypeError: Cannot read property 'reset' of undefined
at F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@uglifyjs-webpack-plugin\dist\index.js:99:22
at F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@uglifyjs-webpack-plugin\dist\index.js:231:9
at Array.forEach (native)
at Compilation.<anonymous> (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@uglifyjs-webpack-plugin\dist\index.js:54:19)
at Compilation.applyPluginsAsyncSeries (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@tapable\lib\Tapable.js:142:13)
at self.applyPluginsAsync.err (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compilation.js:635:10)
at Compilation.applyPluginsAsyncSeries (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@tapable\lib\Tapable.js:131:46)
at sealPart2 (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compilation.js:631:9)
at Compilation.applyPluginsAsyncSeries (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@tapable\lib\Tapable.js:131:46)
at Compilation.seal (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compilation.js:579:8)
at F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compiler.js:493:16
at F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@tapable\lib\Tapable.js:225:11
at _addModuleChain (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compilation.js:481:11)
at processModuleDependencies.err (F:\Github\Program\My-test\Webpack\www2\node_modules\[email protected]@webpack\lib\Compilation.js:452:13)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
The webpack config maybe give some help to you:
module.exports = {
entry: {
app: path.resolve(APP, 'index.js'),
vendors: ['jquery', 'moment']
},
output: {
path: BUILD,
filename: 'bundle.js'
},
plugins: [
new HTMLwebpackPlugin({
title: 'Generate by webpack'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
filename: 'vendors.js'
}),
new UglifyJSPlugin({
compress: true
})
],
module: {
loaders: [
{
test: /\.scss$/,
loaders: 'style-loader!css-loader?sourceMap!sass-loader?sourceMap',
include: APP
},
{
test: /\.(jpg|png)$/,
loaders: 'url-loader?limit=40000'
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
include: APP,
query: {
presets: ['es2015', {"modules": false}]
}
}
]
},
devtool: 'eval-source-map'
}
What's the 'reset' mean? I can't find answer in anywhere... Thanks!
Upvotes: 13
Views: 8467
Reputation: 1285
Its working with webpack3 + angular4 just use
npm install [email protected] --save-dev
Upvotes: 2
Reputation: 14393
Edit august 2017: Now uglifyjs-webpack-plugin works with uglify-js@3
Install the plugin: npm install uglifyjs-webpack-plugin --save-dev
, then, in webpack config:
var UglifyJSPlugin = require('uglifyjs-webpack-plugin')
...
plugins: [
new UglifyJSPlugin()
]
Upvotes: 17
Reputation: 4280
2017-07-26
I solved the issue by:
npm i -D [email protected]
Reason: [email protected]
, which is the version used by webpack
, does not support uglify-js 3. Since [email protected]
, it starts supporting uglify-js 3.
Reference:
Upvotes: 0
Reputation: 6336
I only did this to solve it:
npm install --save-dev uglify-js@2
You have to make sure you're using uglify 2 and not 3.
My config looks like this:
const webpack = require('webpack');
module.exports = {
...
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
};
Upvotes: 4
Reputation: 258
works for me:
npm install uglifyjs-webpack-plugin --save-dev
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
But this is not work:
new UglifyJSPlugin({
compress: true
})
Same question was at Github, the answer was :
Currently using UglifyJS 3 breaks the plugin. It has a new API so the plugin has to change accordingly.
Upvotes: 4