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

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

Open
rightaway opened this issue Jan 1, 2021 · 15 comments
Open

Comments

@rightaway
Copy link

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.

@PJ-CM
Copy link

PJ-CM commented Feb 11, 2021

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

@PJ-CM
Copy link

PJ-CM commented Feb 11, 2021

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/**/*")],
        }),
    ],
};

@evpaassen
Copy link

Is this when using the clean-webpack-plugin together with webpack-dev-server? I'm guessing that Webpack 5 doesn't set output.path when running as dev server, because it keeps the files in memory, so there's nothing to clean. If I'm not mistaken, the solution would probably be to use the clean-webpack-plugin in the production build configuration.

If the author of this module could confirm this, that would be awesome.

@PJ-CM
Copy link

PJ-CM commented Feb 17, 2021

Hi @evpaassen ... And how would it be an example of the code refered to "use the clean-webpack-plugin in the production build configuration."?
The code I put isn't a good solution?

@smashercosmo
Copy link

@PJ-CM this issue is about clean-webpack-plugin not respecting webpack 5 defaults. Your solution is not really a solution to the issue :)

@PJ-CM
Copy link

PJ-CM commented Feb 18, 2021

I think the issue or the question that @rightaway does is about the right configuration of clean-wbpack-plugin for Webpack 5 and how to avoid that mistake.

@smashercosmo
Copy link

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.

@solimant
Copy link

@PJ-CM - your solution works because you've explicitly configured output.path. If you remove it, clean-webpack-plugin will fail to clean up things.

@evpaassen - the behavior is consistent with any kind of build. As @smashercosmo mentioned, clean-webpack-plugin seems to ignore Webpack 5 default output.path, which Webpack 5 upgrade guide calls out to remove if it is path.resolve(__dirname, 'dist'), as that is the default. Once removed (per the Webpack 5 upgrade guide), clean-webpack-plugin stops working, and the build logs show the message:

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

@solimant
Copy link

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.
  },
};

@smashercosmo
Copy link

@solimant coool, didn't know that. thx for the tip)

@PJ-CM
Copy link

PJ-CM commented Feb 18, 2021

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

@solimant
Copy link

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

@PJ-CM
Copy link

PJ-CM commented Feb 18, 2021

That's the version I'm using ... Thank you @solimant . Nothing better than immediate responses.

@madarche
Copy link

See also #197

lluerich added a commit to ampproject/amp.dev that referenced this issue May 12, 2021
sebastianbenz pushed a commit to ampproject/amp.dev that referenced this issue May 12, 2021
* 💄 Add missing breakpoint

* 🚨 Explicitly add output.path

- see johnagan/clean-webpack-plugin#194
Enriqe pushed a commit to Enriqe/amp.dev that referenced this issue May 17, 2021
* 💄 Add missing breakpoint

* 🚨 Explicitly add output.path

- see johnagan/clean-webpack-plugin#194
@rbruckheimer
Copy link

This plugin still has value if using cleanAfterEveryBuildPatterns option, so the original question still stands as to why it is necessary to explicitly specify the output.path.

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

7 participants