Sanity 2.22 deploy fails with heap out of memory error
This is a JavaScript heap memory error that occurs during the build process when deploying your Sanity Studio. The error happens because the terser minification process (which compresses your JavaScript code) is running out of memory. This is a relatively common issue, especially with larger Studio projects or when using Node.js with default memory limits.
Here are several solutions you can try:
1. Increase Node.js Memory Limit (Quickest Fix)
Before running sanity deploy, increase the Node.js heap size:
NODE_OPTIONS="--max-old-space-size=4096" sanity deployThis allocates 4GB of memory instead of the default ~1.5GB. Adjust the number higher if needed (e.g., 8192 for 8GB).
2. Deploy Without Minification
You can build without minification and then deploy the pre-built files:
sanity build --no-minify
sanity deploy --no-buildThe --no-minify flag skips the terser compression step that's causing the memory issue, and --no-build tells deploy to use the already-built files.
3. Upgrade Node.js Version
Newer Node.js versions have better memory management and garbage collection. If you're on an older version (like Node 12 or 14), upgrade to Node 16 or 18, which were commonly used with Sanity Studio v2.
4. Combined Approach
If you need minification but still hit memory limits, combine the approaches:
NODE_OPTIONS="--max-old-space-size=8192" sanity build
sanity deploy --no-buildWhy This Happens
Sanity Studio v2.22 may have added more features or dependencies that increase the bundle size, making the minification process more memory-intensive. The terser library (which minifies JavaScript) needs to load the entire bundle into memory to process it, and with larger Studios, this can exceed Node's default memory limits.
Long-term Consideration
If you're still actively developing this project, consider planning a migration to Sanity Studio v3 or v4, which have significant performance improvements and better build optimization. However, this is a larger undertaking and not necessary to solve your immediate deployment issue.
Try the NODE_OPTIONS approach first—it's the simplest solution that usually works for most cases.
Show original thread2 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.