Search code examples
webpackuglifyjs

unknown property 'optimization'


I'll trying to use uglify with webpack but got this error:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'optimization'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }

I have

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

and

optimization: {
        minimizer: [new UglifyJsPlugin()]
    }

in my webpack.config.js, looks like webpack is not recognizing 'optimization'?


Solution

  • Perhaps you are using an old webpack version (3?) and you might need to put the plug-in instance in the plugin property:

    module.exports = {
        ...
        plugins: [new UglifyJSPlugin()]
    };
    

    Always try to find documentation matching the version you are using or update webpack to a newer version. The current version is 4.19.0 (at 2018-09-17).