copy-webpack-plugin: "Options should be array" error - constructor only takes array args.

  • Operating System: Windows 10
  • Node Version: 6.14.4
  • NPM Version: 14.0.0
  • webpack Version: 4.43.0
  • copy-webpack-plugin Version: 5.1.1

Expected Behavior

It would be expected the documented syntax for the plugin works.

Actual Behavior

If the constructor is structured like the documentation, you get an error like this:

CopyPlugin Invalid Options

options should be array

ValidationError: CopyPlugin Invalid Options
    at validateOptions (C:\Users\user\code\app\node_modules\copy-webpack-plugin\node_modules\schema-utils\src\validateOptions.js:32:11)

Code

Error-causing code:

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: 'source', to: 'dest' },
        { from: 'other', to: 'public' },
      ],
    }),
  ],
};

Good code:

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  plugins: [
        new CopyPlugin(
            [
                { from: 'source', to: 'dest' },
                { from: 'other', to: 'public' },
            ]
        ),
  ],
};

How Do We Reproduce?

Create webpack config with documented syntax.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 104
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I don’t know why this issue was closed - I searched the open issues because of this problem an hour ago, but only found this solution now. The issue is not resolved until the incorrect public documentation has been fixed. Until then, people are going to be trying to understand why this is not working and looking through your open issues and not finding this.

Short answer:

    new CopyWebpackPlugin([
      { from: 'source', to: 'dest' },
    ])

Long answer:

…please use documentation from here https://github.com/webpack-contrib/copy-webpack-plugin/tree/v5.1.1, release will be soon

I can confirm I am having this problem as well.

I see from the git history that you just made a breaking change that hasn’t been released yet, but it’s frustrating and time consuming that I’m working with a freshly installed module and reading the official docs, but it doesn’t work as documented.

Perhaps release branches would reduce these issues.

It’s too much!!!,copy-webpack-plugin 5.1.1 is

new CopyPlugin([
    { from: '...', to: '...' },
])

README.md is

new CopyPlugin({
    patterns: [
        { from: 'source', to: 'dest' },
        { from: 'other', to: 'public' },
    ],
})

https://webpack.js.org/plugins/copy-webpack-plugin/ is still showing the old syntax. gave up and googled. here I am. weird issue to have?

This should absolutely not be closed… This is clearly an issue and this ticket serves as a point of reference for people who have this problem. This should be closed once the change has been merged…

Oh man this just tripped me up for the last hour or so. I was about to downgrade to try and get around this. Thanks!

I’m having the same issue. Please fix.

We have a next branch in master because we prepare next release, please use documentation from here https://github.com/webpack-contrib/copy-webpack-plugin/tree/v5.1.1, release will be soon