Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files are not removed when there is an error in the build #169

Open
tobia opened this issue Nov 29, 2019 · 2 comments
Open

Files are not removed when there is an error in the build #169

tobia opened this issue Nov 29, 2019 · 2 comments

Comments

@tobia
Copy link

tobia commented Nov 29, 2019

The plugin does nothing (does not remove the old files) when there is an error in the build. I think this is a bug.

Steps to reproduce:

  1. Use the following minimal webpack.config.js:
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
  output: { filename: '[name].[contenthash].js' },
  plugins: [ new CleanWebpackPlugin() ]
};
  1. Create a minimal src/index.js with no errors.
  2. Launch webpack in watch mode: the dist folder is populated with only one main.*.js file.
  3. Change src/index.js introducing a syntax error.

Result: the dist folder now has two main.*.js files.

Expected result: the old file is cleaned an only the newest version remains.

Workaround

Remove the following lines from the plugin source code:

    /**
     * Do nothing if there is a webpack error
     */
    if (stats.hasErrors()) {
      if (this.verbose) {
        // eslint-disable-next-line no-console
        console.warn('clean-webpack-plugin: pausing due to webpack errors');
      }

      return;
    }
@toshihidetagami
Copy link

Isn't this expected behavior from v3?

https://github.com/johnagan/clean-webpack-plugin/releases
#134

@Julien-prrs
Copy link

Preventing file deletion can be useful in some cases. However, I think that we should have an option to enable/disable this feature. Because in some case this is more annoying than useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants