Build fails on Github push but succeeds with cleared cache retry
This isn't really a Sanity issue - it's a Netlify build configuration problem with your monorepo setup. The error sh: 1: next: not found combined with npm WARN Local package.json exists, but node_modules missing indicates that Netlify isn't properly installing dependencies in your web folder when using cached builds.
While you have a Sanity Studio in your project, the build failure is happening because Netlify's cache restoration isn't triggering dependency installation correctly for your Next.js application. This is a common Netlify monorepo caching issue.
You'll want to reach out to Netlify support or check their documentation for monorepo build configuration. Some common solutions involve:
- Configuring a
netlify.tomlfile with properbasedirectory settings - Setting the
NPM_CONFIG_PRODUCTIONenvironment variable - Adjusting your build commands to explicitly install dependencies in each workspace
Since this is about Netlify's build process rather than Sanity's functionality, the Netlify support forums or their documentation on monorepo builds would be the best place to get help with this specific issue.
If you were having issues with sanity build or deploying your Sanity Studio specifically, that's where the Sanity community could help - but in this case, your Studio build is actually succeeding; it's the Next.js build that's failing due to Netlify's dependency management.
Show original thread10 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.