Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'?

like image 917
David C Avatar asked Sep 16 '18 23:09

David C


2 Answers

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).

like image 136
Hero Wanders Avatar answered Oct 28 '22 06:10

Hero Wanders


Same happened to me as well, please clear your node_modules and re-install them.

like image 41
Abhinav Singi Avatar answered Oct 28 '22 06:10

Abhinav Singi