laravel-mix: Mix does not delete old versioned files when a new one is generated
- Laravel Mix Version: 0.11.4
- Node Version: v6.10.0
- NPM Version: 3.10.10
- OS: Windows 7 Ultimate 64x
Description:
When I’m using the version() function, it doesn’t matter if I’m running in production mode or not, the old versioned files are not been deleted (BTW this is not a Laravel project)

Steps To Reproduce:
Put this setting in the webpack.mix.js

About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 56 (23 by maintainers)
@warrio4 Things has changed since my comment. I would suggest to use clean-webpack-plugin
webpack-mix.jsThis plugin play nice even in watch mode.its not that they are getting duplicated, its that mix does not delete old versioned files properly, im having the exact same issue.
@boyd91 0.11.4 is the most stable at the moment.
Install rimraff, then add the following scripts to your package.json:
This will ensure that aforementioned directories are cleaned before running asset compilation.
I honestly haven’t read this whole thread, but the 1.0 release of Mix changes the way versioning is applied. Monitoring all these hashed file names is confusing, and makes deployment more difficult for some people.
So now, when you do mix.version(), it’ll just apply a md5’d hash of the file’s contents to the query string. Check your compiled mix-manifest.json file to access them using Laravel’s usual
mix()function.So these changes will automatically resolve this issue, because there’s no old file to delete.
agree with @KonradDeskiewicz … why are we all trying to hack a way to resolve this when it was working perfectly fine before and now something broke
@JeffreyWay is it laravel-mix that is now causing this or is it a break coming from one of its dependencies? if it’s laravel-mix, any plans to revert what caused this?
https://github.com/johnagan/clean-webpack-plugin
I recommend using this and configure it in your
webpack.mix.jsI always look at the package.json at laravel/laravel: https://github.com/laravel/laravel/blob/master/package.json
Also, it helps to delete the node_modules folder and then run
npm installAnd make sure you have the latest version of node/npm installed before running it! (LTS is fine)
IMHO it shouldn’t be hacked. It should be fixed to previous state. I’m currently using older version (0.8.9) just to keep things running as desired.
@ankurk91
I did as suggested. Unfortunately, this deletes correctly all the previous files only when
watchis run. but on the following builts, nothing is being deleted :\ Same case as vesper8I know this problem should be fixed by adding the id param instead of the hash, but I’m encountering a similar problem that is not fixed (I’m using Laravel Mix v5.0.7).
Through the
webpackConfigmethod I’m using thesplitChunksPluginfrom webpack, which reduces duplication between chunks by creating additional chunks when there is enough code in common between modules.This means that in some cases the total number of dynamically added chunks is different between the dev and the prod environment, because in development files are larger, so it’s easier to share more code between the files.
So the fact that the mix-manifest file is not updating when the build removes files is causing some issues (especially when working with other people) and I’d like to share how I solved the issue.
1. Laravel-Mix-Clean
In order to avoid having more files than needed, I’m deleting all the files at each build. I had to change the folder structure and pass the correct path to the method, but this didn’t cause many issues.
and in the mix file
2. Removing the manifest
Having the files in sync was not enough, so I had to remove the manifest file at each new build. In my set-up I have three concurrent builds (each with its own
webpack.mixfile), so I don’t know which one will finish first.The solution was to install the
del-clipackage (which is used internally by theclean-webpack-plugin, which in turn is used bylaravel-mix-clean) and to delete the manifest file before each build.package.json
I hope this helps other people with similar issues.
@younus93 This is fixed in version 1.0, which is already released. Upgrade to fix the issue.
1.0 does no longer create hashed filenames, it just appends a hash as a query param.
@warrio4 I have to do that too. It’s not just you!
@vesper8 For your static/non-generated files, place them in the
resourcesdirectory and use themix.copyDirectory()to copy the files while compiling.@ankurk91 I tried your suggestion and this only cleans the folders when I first run npm run (dev, watch, production)
But on editing files while running ‘npm run watch’ it still continues to pile up the js files
This also had the effect of deleting all my non-generated files that were in those folders…
yep am also having the same problem… caused several problems for me… first I couldn’t push anymore because suddenly I had over 50 large app.js files and I hadn’t picked up on it.
Then my phpstorm started being super sluggish… again because it was indexing 50+ huge minified js files
Finally I found the problem and fixed it… but this is quite a bug that was recently introduced!! Not sure what is causing it exactly but I hope it is patched quickly or else lots of people are gonna have lots of problems
With the following setup the problem is present:
-laravel-mix@0.12.1 -laravel 5.4 -node v6.10.1 -npm 5.0.1 -Windows 10
If I use laravel-mix@0.11.4, all works fine. Somethnig got broken when moving to version 0.12, lets hope it can be solved on a future version.
Same for me. Using the same versions and OS as @jrodalo and also very sure this wasn’t happening before. Or else I would have noticed it in my commits.
I have the same problem with Laravel and I’m sure that this was working some weeks ago. 🤔
-laravel-mix@0.12.1 -laravel 5.4 -node v6.2.0 -npm 5.0.1 -osx
The same happens on another machine with Ubuntu, node v6.3.1 and npm 3.10.3
Steps to reproduce:
Now everytime you change your javascript or css files, versioned files have not been deleted.
@adiachenko @ruchern I need help with this…
I do not know what I’m doing wrong, but when I use the npm run watch or watch-poll, my page is not updating correctly. And ends up generating several compiled files, without removing them.
My Settings: package.json
webpack.mix.js
I’m using Windows 10 + Homestead. When I run the command npm run dev | prod | watch me returns node-sass error. What can it be?
@marvinosswald Instead of
rimraff, useclean-webpack-plugin. It’s made specially for webpack and to cleanup directories based on your configuration. @JeffreyWay used it for one of his Laracasts demo.@steveheinsch I get it. I am not saying Mix shouldn’t fix its issues. I just threw the idea out there, it’s your decision what to do with it.
I have been able to reproduce de problem on versio 0.12.0, on version 0.11.4 all is working fine
Yes, i can reproduce the issue, mix does not delete files if output folder is other than default (public/js).
There are two possible solution for now.
Let files go in default directories.js mix.js('./resources/assets/js/app.js', 'public/js/app.js')