[Support Guide] My site deploy fails unless Netlify's build cache is cleared

Last reviewed by Netlify Support - July 2025

Netlify builds are highly configurable, but you may encounter some common build problem scenarios, which we describe in depth in these two articles:

However, there is an edge case that isn’t mentioned that deserves special treatment: Your build fails every time, UNLESS you manually click “Trigger deploy” > “Clear cache and deploy site” on the deploy listings page or “Options” > “Clear cache and retry deploy” within a specific deploy. This likely indicates another root cause, for example:

  1. You have committed node_modules to your repo which is like committing your kitchen sink. Maybe the dishes are all in there - but they might be dirty and unusable by us a second time. This article has more details about why this is an antipattern (to say that a different way: don’t do it!).
  2. Your dependencies have binary components, which need to be rebuilt for some reason. For instance, if the version of Node.js we use to build changes, any binary modules built against the old version are unlikely to work with the new version - BUT we also may not rebuild them if they are cached already!
  3. We key off seeing package.json OR yarn.lock so having both is an antipattern - we won’t run both for you automatically (see the logic we use in the build script for more details).
  4. You manually manipulate your node_modules directory in some way during install - and that can corrupt the node module cache which we store and attempt to reuse. This is not generally regarded as a good practice and should be avoided for optimal results in our continuous deployment environment.
  5. If you are using yarn workspaces or a monorepo please consult the appropriate documentation (linked to in this sentence).
  6. Fairly rare but worth mentioning: You have a package.json in your repo root, but you are building a subdirectory of your repo and have NOT appropriately set the base directory in your build settings. That can lead to some confusing caching situations since we’ll only sometimes use that package.json (when there is nocache).

If you are still having issues and neither the articles linked at the top, nor these tips are applicable, let us know by posting a new topic, describing your specific situation in detail.

Deploy only works if cache is cleared
[Support Guide] Frequently encountered problems during builds
Build failures on every push except pass on cache rebuild
Builds always fail until clearing cache and re-trying
Every build fails until we "clear cache and retry"
My site deploy fails unless Netlify’s build cache is cleared (Microsoft Rush monorepo)
Build is failing on push but works on "Clean cache and build"
Gatsby build command does not work when deploy without CLEAR CACHE
Site deploy fails unless Netlify’s build cache is cleared
Eleventy builds stopped working
New builds fail with error fetching branch, but "clear cache & deploy site" succeeds
[Support Guide] Compiled Build and Deploy Resources -- start here!
Deploy preview won't build without clearing the cache
Hugo build fails without clearing cache
Build fails on Command failed with exit code 1 or Command failed with exit code 137
Cache builds fail during 'preparing repo' step; "Error fetching branch"
Next.js build works for a bit, then fails, until we clear cache, AWS unzipped size too large
Build fails with ENOENT in a dependency during yarn install
Cache needs to be cleared for build to work
Getting build failure: "Failed to prepare repo"
Build success only after re deploy site with clear cache
New builds fail with error fetching branch, but "clear cache & deploy site" succeeds
Builds always fail until clearing cache and re-trying
Failing build: Failed to prepare repo, failed during stage 'preparing repo': exit status 1
Failing build: Failed to prepare repo
Gatsby & Linaria build fails unless cache is cleared
Jekyll Tailwind integration — conversion error on build

Another fix is to update your package.json scripts to run in order and wait for one to finish before moving to another.

& as in eleventy & npm run tailwind:build - means run both eleventy and npm run tailwind:build at the same time. I don’t care about which script finishes first just run them.

&& as in eleventy && npm run tailwind:build run eleventy wait for eleventy to finish, then run npm run tailwind:build

I found the answer to my problem here: Postinstall script fails using netlify-lambda to install function dependencies · Issue #227 · netlify/netlify-lambda · GitHub.

It seems using netlify-lambda install in postinstall also triggers this problem. It should be moved to prebuild as a work arround.

We are using Nx along with Angular. Recently, I upgraded my project from Angular 17 to Angular 19. However, I’m facing the same issues — I consistently receive a bus error (core dumped) with exit code 135. I’m attaching sample logs for reference.

Failed to remove some directories [
7:54:19 PM: npm warn cleanup   [
7:54:19 PM: npm warn cleanup     '/opt/build/repo/app-v2/node_modules/esbuild',
7:54:19 PM: npm warn cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/opt/build/repo/app-v2/node_modules/esbuild/lib'] {
7:54:19 PM: npm warn cleanup       errno: -39,
7:54:19 PM: npm warn cleanup       code: 'ENOTEMPTY',
7:54:19 PM: npm warn cleanup       syscall: 'rmdir',
7:54:19 PM: npm warn cleanup       path: '/opt/build/repo/app-v2/node_modules/esbuild/lib'
7:54:19 PM: npm warn cleanup     }
7:54:19 PM: npm warn cleanup   ],
7:54:19 PM: npm warn cleanup   [
7:54:19 PM: npm warn cleanup     '/opt/build/repo/app-v2/node_modules',
7:54:19 PM: npm warn cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/opt/build/repo/app-v2/node_modules/@swc'] {
7:54:19 PM: npm warn cleanup       errno: -39,
7:54:19 PM: npm warn cleanup       code: 'ENOTEMPTY',
7:54:19 PM: npm warn cleanup       syscall: 'rmdir',
7:54:19 PM: npm warn cleanup       path: '/opt/build/repo/app-v2/node_modules/@swc'
7:54:19 PM: npm warn cleanup     }
7:54:19 PM: npm warn cleanup   ],
7:54:19 PM: npm warn cleanup   [
7:54:19 PM: npm warn cleanup     '/opt/build/repo/app-v2/node_modules/@swc',
7:54:19 PM: npm warn cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/opt/build/repo/app-v2/node_modules/@swc'] {
7:54:19 PM: npm warn cleanup       errno: -39,
7:54:19 PM: npm warn cleanup       code: 'ENOTEMPTY',
7:54:19 PM: npm warn cleanup       syscall: 'rmdir',
7:54:19 PM: npm warn cleanup       path: '/opt/build/repo/app-v2/node_modules/@swc'
7:54:19 PM: npm warn cleanup     }
7:54:19 PM: npm warn cleanup   ]
7:54:19 PM: npm warn cleanup ]
7:54:19 PM: npm error code 135
7:54:19 PM: npm error path /opt/build/repo/app-v2/node_modules/@nrwl/js/node_modules/nx
7:54:19 PM: npm error command failed
7:54:19 PM: npm error command sh -c node ./bin/post-install
7:54:19 PM: npm error Bus error (core dumped)
 npm error code 135
9:22:30 PM: npm error path /opt/build/repo/app-v2/node_modules/@nrwl/jest/node_modules/nx
9:22:30 PM: npm error command failed
9:22:30 PM: npm error command sh -c node ./bin/post-install
9:22:30 PM: npm error Bus error (core dumped)
Failed to remove some directories [
2:21:54 PM: npm warn cleanup   [
2:21:54 PM: npm warn cleanup     '/opt/build/repo/app-v2/node_modules',
2:21:54 PM: npm warn cleanup     [Error: ENOTEMPTY: directory not empty, rmdir '/opt/build/repo/app-v2/node_modules'] {
2:21:54 PM: npm warn cleanup       errno: -39,
2:21:54 PM: npm warn cleanup       code: 'ENOTEMPTY',
2:21:54 PM: npm warn cleanup       syscall: 'rmdir',
2:21:54 PM: npm warn cleanup       path: '/opt/build/repo/app-v2/node_modules'
2:21:54 PM: npm warn cleanup     }
2:21:54 PM: npm warn cleanup   ]
2:21:54 PM: npm warn cleanup ]
2:21:54 PM: npm error code 135
2:21:54 PM: npm error path /opt/build/repo/app-v2/node_modules/@nrwl/jest/node_modules/nx
2:21:54 PM: npm error command failed
2:21:54 PM: npm error command sh -c node ./bin/post-install
2:21:54 PM: npm error Bus error (core dumped)