npm run dev fails : ValidationError: Invalid options object
This is not an issue with webpack
or webpack-dev-server
itself, but with the copy-webpack-plugin
plugin.
With the update to the 6.x major version came a breaking change: instead of just passing the array with the config patterns directly to the CopyWebpackPlugin
constructor, your now have to wrap it in the patterns
property of an object and pass that.
Old syntax:
new CopyWebpackPlugin( [ { from: 'src/xxx.ext', to: 'dist/xxx.ext' }, { from: 'src/yyy.ext', to: 'dist/yyy.ext' } ] )
New syntax:
new CopyWebpackPlugin( { patterns: [ { from: 'src/xxx.ext', to: 'dist/xxx.ext' }, { from: 'src/yyy.ext', to: 'dist/yyy.ext' } ] } )
They did that because the constructor now supports an additional options
property:https://webpack.js.org/plugins/copy-webpack-plugin/#options-1
After updating to 3.11 a new template appeared
plugins: [ new CopyPlugin({ patterns: [ { from: 'source', to: 'dest' }, { from: 'other', to: 'public' }, ], }), ],
I had the same problem. Finally, I was able to solve it using
npm install --save copy-webpack-plugin@5.1.1