clean-webpack-plugin: clean-webpack-plugin: options.output.path not defined. Plugin disabled...

Issue description or question

With webpack 5.11.1 and clean-webpack-plugin 3.0.0 I get error clean-webpack-plugin: options.output.path not defined. Plugin disabled... when path isn’t defined explicitly in the config file. But https://webpack.js.org/configuration/output/#outputpath defines a default path so is this check necessary? It should use the default path if one isn’t provided explicitly.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 29
  • Comments: 15

Commits related to this issue

Most upvoted comments

It is worth mentioning that beginning Webpack 5.20.0+, there is an output.clean option that cleans the output directory before emit:

module.exports = {
  //...
  output: {
    clean: true, // Clean the output directory before emit.
  },
};

So, finally, with the output.clean option, there is no need to use clean-webpack-plugin, right?

@PJ-CM - if you’re on Webpack 5.20.0+, yes, at least for basic clean-up needs, in my opinion.

I get the same error as @rightaway … What is the solution to apply, please?

No, it’s not about correct configuration. It’s about clean-webpack-plugin not taking into account default output.path value when it’s not explicitly provided.

Finally, that’s how it’s working fine:

const{ CleanWebpackPlugin } = require("clean-webpack-plugin");

const path = require("path");

module.exports = {
    output: {
        path: path.resolve(__dirname, "dist"),
    },
    plugins: [
        new CleanWebpackPlugin({
        cleanOnceBeforeBuildPatterns: [path.join(__dirname, "dist/**/*")],
        }),
    ],
};