v3, return of "TypeError: CleanWebpackPlugin is not a constructor #143" ?
pgnd opened this issue · comments
I'm currently seeing the same error as closed/locked
"TypeError: CleanWebpackPlugin is not a constructor #143"
here, with
npx envinfo --system --binaries --npmPackages clean-webpack-plugin,webpack
npx: installed 1 in 1.979s
System:
OS: Linux 5.2 openSUSE Leap 15.1
CPU: (4) x64 AMD Phenom(tm) II X4 945 Processor
Memory: 384.31 MB / 15.64 GB
Container: Yes
Shell: 4.4.23 - /bin/bash
Binaries:
Node: 12.7.0 - /usr/local/nodejs/bin/node
Yarn: 1.17.3 - /usr/local/yarn/bin/yarn
npm: 6.10.0 - /usr/local/nodejs/bin/npm
npmPackages:
clean-webpack-plugin: ^3.0.0 => 3.0.0
webpack: ^4.39.1 => 4.39.1
and
webpack.js
...
const CleanWebpackPlugin = require('clean-webpack-plugin');
...
on exec, still
./node_modules/webpack-cli/bin/cli.js --env development --debug --progress
/srv/www/test01/node_modules/webpack-cli/bin/cli.js:93
throw err;
^
TypeError: CleanWebpackPlugin is not a constructor
...
is this a new-, or re-, occurrence? or, something obvious I'd missed ?
Since v3 we’ve moved to a named export. Try:
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
chaging my existing, previously working config
- const CleanWebpackPlugin = require('clean-webpack-plugin');
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
exports.clean = path => ({
plugins: [
new CleanWebpackPlugin(
path,
{
dry: false,
verbose: true,
watch: false,
exclude: [],
allowExternal: false,
beforeEmit: false
}
)
],
});
and clears the constructor error.
but, now returns,
Error: clean-webpack-plugin only accepts an options object. See:
https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional
1st, just fyi, THAT^^ tag is incorrect; should be
https://github.com/johnagan/clean-webpack-plugin#user-content-options-and-defaults-optional
What's the correct usage now for the options object? If I've missed a doc/example somewhere, could you pls point?
Please read: #106
My guess is you can replace your config with:
new CleanWebpackPlugin({
dry: true, // remove this once you verify it removes the correct files
verbose: true,
});
@pgnd is your issue resolved?
Minor add'l tweak did the trick here
with explicit config,
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
exports.clean = path => ({
plugins: [
new CleanWebpackPlugin({
dry: false,
verbose: true,
cleanStaleWebpackAssets: true,
protectWebpackAssets: false,
cleanOnceBeforeBuildPatterns: ['**/*'],
})
],
});
exec of
parts.clean([
PATHS.build,
PATHS.cache,
etc
etc
]),
works a charm!
o/
That's great. FYI, your path
param doesn't do anything.
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
exports.clean = () => ({
plugins: [
new CleanWebpackPlugin({
dry: false,
verbose: true,
cleanStaleWebpackAssets: true, // this can be removed as it is the default
protectWebpackAssets: false, // I do not see you removing non-webpack assets, not sure why this is set to false.
cleanOnceBeforeBuildPatterns: ['**/*'], // this can be removed as it is the default
})
],
});
parts.clean();
it only worked me when I tried this stackoverflow answer that has the most upvotes and $npm start
(or whatever start means in your package.json)