MaxListenersExceededWarning and JSON parse error during Sanity export

14 replies
Last updated: Nov 29, 2025
Exporting dataset "dev" to "/tmp/sanity_export_module.tar.gz"
⠴ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠙ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠴ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠇ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠴ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠏ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠙ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠸ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠧ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠼ Exporting documents... (17/?)(node:68190) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
⠧ Exporting documents... (17/?)Unhandled rejection: SyntaxError: Unexpected end of JSON input ({"_createdAt":"2020-06-10T17:02:35Z","_id":"MmjVXHtlNsZV9S0PqvTXd5","_rev":"MmjVXHtlNsZV9S0PqvTXZo","_type":"mux.videoAsset","_updatedAt":"2020-06-10T17:02:35Z","assetId":"go2Jg936QgKew702LqdShzPI400rE4wbhh","data":{"aspect_ratio":"25:56","created_at":159)
    at JSON.parse (<anonymous>)
    at DestroyableTransform.module.exports [as mapper] (/###/node_modules/@sanity/export/lib/tryParseJson.js:5:17)
    at DestroyableTransform.flush [as _flush] (/###/node_modules/split2/index.js:44:21)
    at DestroyableTransform.prefinish (/###/node_modules/readable-stream/lib/_stream_transform.js:138:10)
    at DestroyableTransform.emit (events.js:311:20)
    at prefinish (/###/node_modules/readable-stream/lib/_stream_writable.js:619:14)
    at finishMaybe (/###/node_modules/readable-stream/lib/_stream_writable.js:627:5)
    at afterWrite (/###/node_modules/readable-stream/lib/_stream_writable.js:492:3)
    at onwrite (/###/node_modules/readable-stream/lib/_stream_writable.js:483:7)
    at WritableState.onwrite (/###/node_modules/readable-stream/lib/_stream_writable.js:180:5)
⠋ Exporting documents... (17/?)
AI Update

This error occurs when the sanity dataset export command encounters a corrupted or truncated JSON response from the Sanity API. The "Unexpected end of JSON input" shows that a document (in your case, a mux.videoAsset document) was cut off mid-stream during export.

Good news: This was a known bug that has been fixed!

According to this community answer, this exact issue was identified and resolved in Sanity CLI version 1.149.17 (released June 2020). The fix not only resolved the error but also significantly improved export performance.

Quick Solutions

1. Update your Sanity CLI (most important):

npm install -g @sanity/cli@latest

This should resolve the issue entirely. After updating, try your export again.

2. Export without assets (temporary workaround):

sanity dataset export dev --no-assets dev-documents-only.tar.gz

As you discovered, the --no-assets flag works because the issue typically occurs when streaming large asset data. This exports only your documents and skips asset files.

3. Use --no-compress (if you need assets):

sanity dataset export dev --no-compress

This can sometimes help with streaming issues.

About the MaxListenersExceededWarning

The MaxListenersExceededWarning you're seeing indicates the export process is creating many simultaneous connections. While this warning itself isn't fatal, it's a symptom of the underlying bug that was causing the JSON parsing failure.

If Problems Persist After Updating

  • Check your Sanity CLI version with sanity versions
  • Try exporting during off-peak hours when API load is lower
  • For very large datasets on Enterprise plans, consider using Cloud Clone which duplicates datasets server-side
  • Contact Sanity support if you continue experiencing issues

The export file that was created is likely incomplete and shouldn't be used for restoration without verification.

Show original thread
14 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?