copy-webpack-plugin: Plugin goes into a loop and build doesn't complete

  • Operating System: Mac / Sierra
  • Node Version: v8.11.1
  • NPM Version: 6.1.0
  • webpack Version: 3.2.1
  • copy-webpack-plugin Version: 5.0.0

Expected Behavior

The copy webpack plugin runs and then the watch stops until further activity

Actual Behavior

The build goes into a loop:

loooooooooooooop :(

Code

This is a Vue CLI 3 build using Webpack Chain:

    // copy all files from all module `plugins` folders  
    // @see https://github.com/webpack-contrib/copy-webpack-plugin
    config.plugins.push(new CopyPlugin([
      {
        from: 'src/modules/*/plugins/*.js',
        to: 'plugins',
        flatten: true,
      },
    ]))

How Do We Reproduce?

Let me know if you need more info and I will look into this.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

@evilebottnawi: upgrading to v5.0.1 seems to resolve the issue. shipit! 😃

Thank you @vonBrax for the instructions. That helped a lot. I’ll illustrate the changes I made:

Before:

    new CopyWebpackPlugin(
      [
        {
          from: 'node_modules/some-external-package/dist/**/*',
          to: 'webWorkerSupport/',
        },
        {
          context: 'src/',
          from: 'someInternalDirectory/images/**/*',
          to: '',
        },
      ],
      undefined
    ),

After:

    new CopyWebpackPlugin(
      [
        {
          context: 'node_modules/some-external-package/dist/',
          from: '**/*',
          to: 'webWorkerSupport/node_modules/some-external-package/dist/',
        },
        {
          context: 'src/someInternalDirectory/images/',
          from: '**/*',
          to: 'someInternalDirectory/images/',
        },
      ],
      undefined
    ),

If someone is still facing this problem maybe this can help. I spent the whole day yesterday trying to figure out why webpack was entering the infinite rebuild loop or why now every file outside of webpack context (including webpack.config) was triggering rebuilds on change. All of this started after I updated a bunch of dependencies at once and so I had to roll back and reupdate one at a time until finding that it happened after updating to v5 of copy-webpack-plugin. In my case the problem was that I was not passing in the context property to the plugin and using a glob for the from property to copy some files in some deep nested subdirectories. By taking a look in the PR pointed above ( #333 ) I saw that it is pushing the context to the webpack dependencies every time you use a glob (if you would pass in the files manually the condition would not be met and this would never happen) which in my case basically meant adding my root folder (and everything inside of it) to be watched by webpack since I was not defining context. And the output of html-webpack-plugin was being detected and triggering the infinite loop. The solution that worked for me was to pass the context property as close as possible to where the files were in the subdirectories tree, right before the glob pattern. Not sure if that’s the best way to do it or if I even need these folders to be watched for changes since I rarely add or remove files from there. For my use case it seems like it is unnecessarily consuming resources and it would be nice if watching these folders was optional.

@evilebottnawi: thank you for looking into it, investing time in fixing it and sharing it with us. once you will release a new package\version, i will update and report back.

thanks again!