Laravel Vite watcher crashing on SCSS changes - EBUSY error and manual restart required

Hey everyone, I’m having trouble with my Laravel Vite setup. Every time I save changes to an SCSS file, the npm run watch command crashes. It’s giving me an EBUSY error, saying a file is locked. The weird thing is, it’s not always the same file.

Here’s what the error looks like:

EBUSY: resource busy or locked, unlink 'C:\...\some-random-file.js'

I’ve tried a bunch of things to fix it:

  • Turned off Windows Defender
  • Deleted and rebuilt the public/build folder
  • Cleared out my Temp folder
  • Restarted everything
  • Ran the command as admin

Nothing seems to work for long. I have to keep restarting the watcher manually after each change, which is super annoying.

Does anyone know how to stop this from happening? I just want to be able to work on my SCSS without the watcher crashing all the time. Any ideas would be awesome. Thanks!

yo, i’ve had this same issue b4. try using the --force flag when running npm run watch. it kinda brute forces through those locked file probs. also, check if ur using any weird characters in ur file names. windows can be picky bout that stuff. if nothin else works, maybe try switchin to WSL for development. good luck man!

I’ve encountered similar issues with Laravel Vite on Windows. One solution that worked for me was adjusting the polling interval in the vite.config.js file. Try adding this to your configuration:

export default defineConfig({
    server: {
        watch: {
            usePolling: true,
            interval: 1000,
        },
    },
    // ... other config options
});

This forces Vite to use polling instead of file system events, which can be more reliable on Windows. It might slow down the recompilation slightly, but it should prevent the EBUSY errors. If that doesn’t work, you might want to check if any antivirus software is interfering with file access. Temporarily disabling it could help isolate the issue.

I’ve dealt with this frustrating issue before in my Laravel projects. One thing that helped me was running the watcher with the --no-watch flag and then manually triggering rebuilds. It’s not ideal, but it got me unstuck.

Another approach that worked was switching to using Laravel Mix instead of Vite temporarily. It’s a bit older but more stable on Windows in my experience.

If you’re set on using Vite, try clearing your npm cache completely and reinstalling dependencies. Sometimes stale packages can cause weird behaviors.

Lastly, check your file paths. I once had a similar error because of an overly long directory structure. Moving the project closer to the root directory resolved it for me.

Hope one of these helps you out. Debugging build tool issues can be a real pain!