can1357/oh-my-pi · error · ArchiveError
ASAR archive is too large to encode in memory
Error message
ASAR archive is too large to encode in memory
What it means
encodeAsar builds the entire ASAR archive as a single in-memory Uint8Array. Before allocating, it validates the total archive size is a safe integer, then attempts `new Uint8Array(archiveSize)`. If that allocation fails (RangeError from the JS engine), the library wraps the failure as ArchiveError("ASAR archive is too large to encode in memory"), because the encoder API is memory-buffer based and cannot stream output.
Source
Thrown at packages/utils/src/ar/asar.ts:463
}
const jsonBytes = ASAR_HEADER_ENCODER.encode(JSON.stringify(root));
const paddedJsonSize = alignAsarPayload(jsonBytes.byteLength);
const innerPayloadSize = 4 + paddedJsonSize;
const headerSize = 4 + innerPayloadSize;
if (jsonBytes.byteLength > 0xffffffff || headerSize > 0xffffffff) {
throw new ArchiveError("ASAR header is too large to encode");
}
const dataOffset = ASAR_PICKLE_PREFIX_SIZE + headerSize;
const archiveSize = dataOffset + payloadSize;
if (!Number.isSafeInteger(archiveSize)) {
throw new ArchiveError("ASAR archive is too large to encode safely");
}
let output: Uint8Array;
try {
output = new Uint8Array(archiveSize);
} catch {
throw new ArchiveError("ASAR archive is too large to encode in memory");
}
writeUInt32LE(output, 0, 4);
writeUInt32LE(output, 4, headerSize);
writeUInt32LE(output, 8, innerPayloadSize);
writeUInt32LE(output, 12, jsonBytes.byteLength);
output.set(jsonBytes, ASAR_JSON_OFFSET);
let offset = dataOffset;
for (const payload of payloads) {
output.set(payload, offset);
offset += payload.byteLength;
}
return output;
} catch (error) {
if (error instanceof ArchiveError) throw error;
throw new ArchiveError(`Failed to encode ASAR archive: ${describeError(error)}`);
}
}
View on GitHub (pinned to 9690622007)
Solutions
- Reduce the total payload size: exclude large binaries/assets from the archive and ship them separately.
- Split the content into multiple smaller ASAR archives.
- Increase the Node/Bun memory headroom for the process (e.g. larger heap, containers with more RAM) if the size is legitimate.
- Use a streaming or file-backed archiver instead of this in-memory encoder for very large payloads.
Example fix
// before
const archive = encodeAsar(members); // members include node_modules with multi-GB artifacts
// after
const smallMembers = new Map([...members].filter(([path]) => !path.startsWith("assets/videos/")));
const archive = encodeAsar(smallMembers); // exclude bulk assets, ship them separately Defensive patterns
Strategy: validation
Validate before calling
const totalBytes = [...members.values()].reduce((n, b) => n + b.byteLength, 0);
if (!Number.isSafeInteger(totalBytes) || totalBytes > MAX_IN_MEMORY_ARCHIVE_BYTES) {
throw new Error(`archive too large for in-memory encode: ${totalBytes} bytes`);
} Type guard
null
Try / catch
try {
const archive = encodeAsar(members);
} catch (err) {
if (err instanceof ArchiveError && err.message.includes("too large to encode in memory")) {
// fall back to streaming/file-based packaging
} else throw err;
} Prevention
- Sum member byte lengths before encoding and enforce a size budget.
- Exclude bulk assets (videos, prebuilt binaries) from ASAR and ship them outside.
- Monitor process memory; run packaging in a high-RAM environment for large apps.
- Prefer a streaming archiver for anything near the GB scale.
When it happens
Trigger: Calling encodeAsar (directly or via encodeArchive/bytes) with a member set whose combined payload size plus header exceeds available memory — e.g. many multi-GB files, or a total size near the safe-integer limit where a contiguous ArrayBuffer cannot be allocated.
Common situations: Packaging huge Electron app directories where the sum of file sizes exceeds the process heap/ArrayBuffer limits; running in memory-constrained environments (containers, low-RAM CI runners); accidentally passing the same large file many times or building member lists in a loop without deduplication.
Related errors
- ASAR member '${formatArchivePathForError(memberPath)}' faile
- ASAR member '${formatArchivePathForError(memberPath)}' has a
- Failed to read ASAR member '${formatArchivePathForError(memb
- ASAR member '${formatArchivePathForError(memberPath)}' is tr
- ASAR member '${label}' has an inconsistent size
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e4f25fec6882ce71.
Report an issue: GitHub.