Sanity 2.22 deploy fails with heap out of memory error

2 replies
Last updated: Nov 26, 2021
Hi Guys, after I updated Sanity to latest version (2.22) , I cannot deploy Sanity using CLI using
sanity deploy
. I'm getting following error. Please help me to find a solution.
<--- Last few GCs --->


[13928:000001F842220080]   608769 ms: Mark-sweep 2024.3 (2073.1) -> 2010.5 (2074.1) MB, 3101.4 / 0.3 ms  (average mu = 0.121, current mu = 0.025) allocation failure scavenge might not succeed

[13928:000001F842220080]   612216 ms: Mark-sweep 2025.3 (2074.1) -> 2011.6 (2075.1) MB, 3346.8 / 0.2 ms  (average mu = 0.076, current mu = 0.029) allocation failure scavenge might not succeed



<--- JS stacktrace --->


==== JS stack trace =========================================


0: ExitFrame [pc: 00007FF72D7DD08D]

1: StubFrame [pc: 00007FF72D7BD7DE]

Security context: 0x0140036808d1 <JSObject>

2: split [000001400368CD51](this=0x01946bc810c9 <String[1]: +>,0x016f1999a631 <JSRegExp <String[#5]: \r?\n>>)

3: print [000000A1B2C90239] [D:\UPN\Repo\Sanity Studio\upnorway-sanity-studio\node_modules\terser\dist\bundle.min.js:~7241] [pc=00000355748CFC97](this=0x00a1b2c90279 <Object map = 000001FBE4652CC9>,0x...


FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

1: 00007FF72CBA288F napi_wrap+119263

2: 00007FF72CB49556 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NextTableOffset+38102

3: 00007FF72CB4A356 node::OnFatalError+438

4: 00007FF72D387B5E v8::Isolate::ReportExternalAllocationLimitReached+94

5: 00007FF72D36FD11 v8::SharedArrayBuffer::Externalize+833

6: 00007FF72D2214EC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436

7: 00007FF72D22C730 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312

8: 00007FF72D229244 v8::internal::Heap::PageFlagsAreConsistent+3204

9: 00007FF72D21EA43 v8::internal::Heap::CollectGarbage+1283

10: 00007FF72D21D0B4 v8::internal::Heap::AddRetainedMap+2500

11: 00007FF72D23E3FD v8::internal::factory::NewFillerObject+61

12: 00007FF72CFA19F1 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1665

13: 00007FF72D7DD08D v8::internal::SetupIsolateDelegate::SetupHeap+546925

14: 00007FF72D7BD7DE v8::internal::SetupIsolateDelegate::SetupHeap+417726

15: 00007FF72D7CA672 v8::internal::SetupIsolateDelegate::SetupHeap+470610

16: 00000355748CFC97
AI Update

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 deploy

This 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-build

The --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-build

Why 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 thread
2 replies
Hi guys, after deleting node modules and installing again , I was able to solve this problem. Thank You 🙂
Glad to hear, Sashini! Thanks for letting us know 🙂

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.

Was this answer helpful?