You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
output.clean : true is not working with dev server #861
output.clean: true is not working with webpack dev server, when building for the first time, or when project is rebuilding due to sources change.
Description
I was trying to configure webpack to clean the dis folder for one of my projects, and decided to use brand new output.clean configuration as I'm using "webpack": "^5.21.2" and this config is supported starting from version 5.20
Config works fine in production build, but when I start webpack dev server with writeToDisk: true webpack doesn't clean the dist/ directory neither upon the start of the dev server nor upon project rebuild.
Initially I though that it might be not supposed to work with dev server, but changing
output: {
...
clean: true},
to
output: {
...
clean: {dry: true,}},
does log what files it should delete when rebuilding project:
If the current behavior is a bug, please provide the steps to reproduce.
Reacted by BrenoES, Kumar Deepak, Carlos Monti, Aaron Conlon, Jason Axelson, Adrian Widerski, Vaughan Rouesnel, Jiří Brabec, Levan Tskipuri and nyngwang
Hello :)
Just to let you know that I have the same issue with clean: true, but with webpack-hot-middleware which doesn't use webpack-dev-server but only webpack-dev-middleware.
When I use webpack from cli, it works.
When I use the process as a middleware, it works for my asset/resource type in module, but it doesn't for the js files from the output configuration, these files are generated again each time without deletion.
Interesting note, I've been using Clean Webpack Plugin while waiting for a solution here, but noticed that after initial bundling, an asset is still available on the localhost even though it's not shown in the file tree. I can still access that asset directly by visiting the link to it in the browser. This was resolved when I set the output.clean: true in my webpack config.
Still an issue with webpack 5.74.0 and webpack-dev-server 4.11.1.
Clean Webpack Plugin isn't working for me either.
I'm not sure if it's because my path is not a static path, as it is based on a version number from the previous git commit, so I have multiple build/app/:version folders that never get cleared? So the more commits I make the more folders I have.
Sorry for delay, I am looking for a solution before the next webpack-dev-server release (with the latest version of webpack-dev-server)
@AaronMcCloskey It doesn't work because you use path: path.resolve(__dirname, build/${ASSET_PATH}), i.e. CleanWebpackPlugin and webpack's output.clean try to remove files insidepath.resolve(__dirname, build/${ASSET_PATH}).
Based on your configuration it is expected, so you allow to download old version of your application, anyway if you want to make it work you need to specify filename: ${ASSET_PATH}/[name].[fullhash].js (same for chunkFilename/assetsFilename and other *filename options) and path: path.resolve(__dirname, "build"), so the root of your assets will be the build directory and everything inside will be cleaned, but your problem is not related to report
Fixed: when you have writeToDisk: true, still have some limitations:
If you don't have writeToDisk option and still see the dist directory it's because we try to avoid extra removing due perf reasons, because it is development enviroments
If you have writeToDisk: (pathToFile) => /regexp/.test(pathToFile) still buggy
Activity
alexander-akait commentedon Mar 22, 2021
I have ideas how we can fix it, but need more time, idea:
so we will have layer layered file system (memory + real fs)
daniele-orlando commentedon May 5, 2021
I can reproduce the problem with Webpack
5.36.mateusz-owczarek commentedon May 7, 2021
I can reproduce that too with
webpack 5.36.2andwebpack-dev-server 3.11.2and the configuration:aetherplex commentedon Aug 27, 2021
Any updates on this? Still an issue with
webpack 5.51.1andwebpack-dev-middleware 5.0.0.alexander-akait commentedon Aug 30, 2021
No, it will be fixed in near future, we need layer fs
josudoey commentedon Nov 13, 2021
the
output.cleanrelease at webpack v5.20.0 and the issue already exists.ahmafi commentedon Dec 25, 2021
Same problem on webpack 5.65.0 and webpack-dev-server 4.6.0
rudyhuynh commentedon Jan 27, 2022
I just keep using clean-webpack-plugin then.
chavlji commentedon Feb 24, 2022
:(
dgpt commentedon Apr 6, 2022
Still a bug as of
webpack 5.71.0andwebpack-dev-server 4.7.4VinnyFonseca commentedon May 11, 2022
9 months later and still nothing. Is this "near future"?
Still happening with
webpack 5.72.0andwebpack-dev-server 4.9.0.jcreek commentedon Oct 7, 2022
Still happening for me with
webpack 5.73.0andwebpack-dev-server 4.9.2.BigFax commentedon Oct 26, 2022
Hello :)
Just to let you know that I have the same issue with
clean: true, but withwebpack-hot-middlewarewhich doesn't usewebpack-dev-serverbut onlywebpack-dev-middleware.When I use webpack from cli, it works.
When I use the process as a middleware, it works for my
asset/resourcetype inmodule, but it doesn't for the js files from theoutputconfiguration, these files are generated again each time without deletion.Clean Webpack Plugin works fine from cli & from middleware.
webpack : 5.74.0
webpack-dev-middleware : 5.3.3
webpack-hot-middleware : 2.25.0
puranjayjain commentedon Oct 27, 2022
Still happens with me as well
brycekunkel commentedon Nov 10, 2022
Interesting note, I've been using Clean Webpack Plugin while waiting for a solution here, but noticed that after initial bundling, an asset is still available on the localhost even though it's not shown in the file tree. I can still access that asset directly by visiting the link to it in the browser. This was resolved when I set the
output.clean: truein my webpack config.AaronMcCloskey commentedon Jan 6, 2023
Still an issue with
webpack 5.74.0andwebpack-dev-server 4.11.1.Clean Webpack Plugin isn't working for me either.
I'm not sure if it's because my path is not a static path, as it is based on a version number from the previous git commit, so I have multiple
build/app/:versionfolders that never get cleared? So the more commits I make the more folders I have.alexander-akait commentedon May 2, 2023
Sorry for delay, I am looking for a solution before the next webpack-dev-server release (with the latest version of
webpack-dev-server)@AaronMcCloskey It doesn't work because you use
path: path.resolve(__dirname,build/${ASSET_PATH}), i.e.CleanWebpackPluginand webpack'soutput.cleantry to remove files insidepath.resolve(__dirname,build/${ASSET_PATH}).Based on your configuration it is expected, so you allow to download old version of your application, anyway if you want to make it work you need to specify
filename: ${ASSET_PATH}/[name].[fullhash].js(same forchunkFilename/assetsFilenameand other*filenameoptions) andpath: path.resolve(__dirname, "build"), so therootof your assets will be thebuilddirectory and everything inside will be cleaned, but your problem is not related to reportalexander-akait commentedon May 3, 2023
Fixed: when you have
writeToDisk: true, still have some limitations:writeToDiskoption and still see thedistdirectory it's because we try to avoid extra removing due perf reasons, because it is development enviromentswriteToDisk: (pathToFile) => /regexp/.test(pathToFile)still buggyolosegres commentedon Jan 30, 2024
@alexander-akait
Bug still preset in
webpack@5.90.0when it runs viawebpack serveand when we have bothoutput.clean: trueandwriteToDisk: truealexander-akait commentedon Jan 30, 2024
@olosegres Please provide reproducible test repo,
writeToDisk: truewas fixed a long time ago