Skip to content

[BUG]When the "context" directory does not exist, the second build of webpack watch will be triggered. #806

@mackwang112

Description

@mackwang112

Bug report

My copy-webpack-plugin configuration is as follows, note that in fact, I do not have this static directory.

new CopyPlugin({
  patterns: [
    {
      context: path.resolve('./static'),
      from: '**/*',
      to: path.resolve('./dist'),
      noErrorOnMissing: true
    }
  ],
})

Actual Behavior

Received the error unable to locate '/Users/Desktop/demo/webpack-demo/static/**/*' glob, but the build was run twice, and the error was output twice as well.

➜  npx webpack --watch
assets by status 28 bytes [cached] 1 asset
./src/main.js 27 bytes [built] [code generated]

ERROR in unable to locate '/Users/Desktop/demo/webpack-demo/static/**/*' glob

webpack 5.101.0 compiled with 1 error in 135 ms
assets by status 28 bytes [cached] 1 asset
./src/main.js 27 bytes [built] [code generated]

ERROR in unable to locate '/Users/Desktop/demo/webpack-demo/static/**/*' glob

webpack 5.101.0 compiled with 1 error in 56 ms

Expected Behavior

Expected to receive unable to locate '/Users/Desktop/demo/webpack-demo/static/**/*' glob error,
but the build was triggered only once.

How Do We Reproduce?

https://github.com/kimi233/webpack-demo1

This is my code repository, use npm run watch to reproduce this issue.

Please paste the results of npx webpack-cli info here, and mention other relevant information.

  System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 66.17 MB / 18.00 GB
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    pnpm: 8.15.9 - ~/.nvm/versions/node/v20.11.0/bin/pnpm
  Browsers:
    Chrome: 138.0.7204.184
    Safari: 17.6
  Packages:
    copy-webpack-plugin: ^13.0.0 => 13.0.0 
    webpack: ^5.101.0 => 5.101.0 
    webpack-cli: ^6.0.1 => 6.0.1 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions