# RangeError: Invalid string length

**Code:** `invalid string length` · **Category:** JavaScript · **Seen on:** JavaScript

A string grew beyond the engine’s maximum length — usually runaway concatenation or huge JSON.stringify output.

## Meaning

V8 strings max out around 512 MB–1 GB. Infinite loops appending text or stringifying massive objects hit the limit.

## Common causes

- Infinite loop concatenating
- JSON.stringify of very large data
- Reading a huge file into one string

## Quick fix

1. Stream large data instead of building one string
2. Fix runaway loops
3. Paginate/chunk exports

## Detailed fix by platform

### Node.js

1. Use streams (fs.createWriteStream, stream.pipeline) for large outputs

## How to diagnose

1. **Size** — How large is the data?
2. **Loop** — Is something appending forever?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/javascript/rangeerror-invalid-string-length)
