Gatsby "Invalid string length" error with unknown document ID from Sanity

2 replies
Last updated: Jan 28, 2026
a gatsby site I’m working on started crashing this morning, which is weird since no code has been changed between today and yesterday and the site worked fine yesterday.
I’m getting a cryptic error stating

 ERROR 

dbb54862-d17c-4e11-a1f0-701364e617ac


 ERROR 

Invalid string length



  RangeError: Invalid string length
  
  - JSON.stringify
  
  - query-runner.js:130 queryRunner
    [web]/[gatsby]/dist/query/query-runner.js:130:27
  
  - task_queues.js:97 processTicksAndRejections
    internal/process/task_queues.js:97:5
  
  - task_queues.js:66 runNextTicks
    internal/process/task_queues.js:66:3
  
  - timers.js:429 processImmediate
    internal/timers.js:429:9
  


 ERROR 

UNHANDLED REJECTION Cannot read property 'sourceMessage' of undefined



  TypeError: Cannot read property 'sourceMessage' of undefined
  
I tried to find a sanity document matching that ID through sanity cli but it could not find any documents matching that ID. I have no idea where the error is so any tips are appriciated! Full error in comments


➜  studio git:(master) sanity documents get dbb54862-d17c-4e11-a1f0-701364e617ac
Error: Failed to fetch document:
Document not found
AI Update

This is a frustrating issue, especially when nothing in your code changed! The "Invalid string length" error at query-runner.js:130 with JSON.stringify typically indicates that Gatsby is trying to serialize data that exceeds JavaScript's maximum string size limits. Since the site worked yesterday and broke today without code changes, this almost certainly points to a content change in Sanity.

Why the UUID Isn't Helpful

The UUID dbb54862-d17c-4e11-a1f0-701364e617ac in the error message appears to be Gatsby's internal error ID rather than a Sanity document ID, which is why sanity documents get couldn't find it. This makes debugging tricky because Gatsby isn't directly telling you which document or query is causing the problem.

Most Likely Causes

Since no code changed, someone probably:

  • Uploaded an extremely large image or file
  • Added a massive amount of content to a document
  • Created or modified a document with very large array fields
  • Edited a document that's now triggering a query to return too much data

Troubleshooting Steps

1. Check Recent Sanity Content Changes

In your Sanity Studio, look at the document history to see what was modified in the last 24 hours. Look for:

  • New or updated documents
  • Large image uploads
  • Documents with extensive arrays or portable text blocks

2. Find Your Largest Documents

Run this GROQ query in Vision (your Studio's query tool) to identify potentially problematic documents:

*[!(_id in path("_.**"))] {
  _id,
  _type,
  "approximateSize": length(string::split(string(*), ""))
} | order(approximateSize desc)[0...20]

This gives you a rough idea of which documents are largest by character count.

3. Review gatsby-source-sanity Configuration

Check your gatsby-config.js to see if you're pulling more data than necessary:

{
  resolve: 'gatsby-source-sanity',
  options: {
    projectId: 'your-project-id',
    dataset: 'your-dataset',
    overlayDrafts: false, // Try disabling if you have this enabled
    watchMode: false,
  }
}

4. Increase Node Memory (Temporary Fix)

While you investigate, you might be able to get builds working again by increasing Node's memory allocation:

NODE_OPTIONS="--max-old-space-size=8192" gatsby build

This isn't a permanent solution but can help you get unblocked while you identify the root cause.

Longer-Term Solutions

Once you identify the problematic content:

  • Split large documents: Break oversized documents into smaller, related pieces
  • Optimize image handling: Ensure you're using Sanity's image pipeline properly and not embedding raw image data
  • Limit query scope: If a specific document type is causing issues, consider filtering it in your GraphQL queries or excluding it from gatsby-source-sanity
  • Review array fields: Documents with hundreds or thousands of array items can grow very large when serialized

Additional Debugging

If you're still stuck, try temporarily removing gatsby-source-sanity from your config and rebuilding to confirm that's where the issue originates. Then add it back with a more restrictive configuration to narrow down which content is problematic.

The combination of "worked yesterday, broken today" + "no code changes" makes this almost certainly a content issue rather than a configuration problem. Start with your Sanity Studio's recent history—that's your best bet for finding the culprit quickly.

Show original thread
2 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.

Was this answer helpful?