oven-sh/bun · error

Unhandled out of memory error in breakOutputIntoPieces()

Error message

Unhandled out of memory error in breakOutputIntoPieces()

What it means

breakOutputIntoPieces() performs allocations that are not individually fallible-checked; if the allocator returns OOM here the code panics with this message rather than propagating an error. It means the process ran out of memory while splitting a printed chunk into output pieces.

Solutions

  1. Reduce bundle size or split the build into smaller entry points to lower peak memory
  2. Increase available memory / raise container limits
  3. Track memory with a profile; very large single chunks are the usual trigger
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/bundler/linker_context/postProcessJSChunk.rs:680 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/31005fd2050bedd9. Report an issue: GitHub.

Appendix: source

Thrown at src/bundler/linker_context/postProcessJSChunk.rs:680

        }
        j.push_static(c.options.footer);
        line_offset.advance(c.options.footer);
        j.push_static(b"\n");
        line_offset.advance(b"\n");
    }

    // SAFETY: every borrowed node in `j` points into `chunk.compile_results_for_chunk`
    // (slots pre-sized in generateChunksInParallel, filled in place by the print
    // workers before post-processing, never reassigned afterwards), `c.options`
    // banner/footer (`&'static`), graph/parse-graph data (hashbangs, source paths,
    // HMR runtime), or `'static` literals; `watcher.input` is `chunk.unique_key`
    // (`&'static`). All of these outlive the joiner stored in
    // `chunk.intermediate_output`, which is only read while the chunk and the
    // linker graph are alive.
    let mut j = unsafe { j.detach_lifetime() };
    chunk.intermediate_output = c
        .break_output_into_pieces(worker_arena, &mut j, ctx.chunks.len() as u32)
        .unwrap_or_else(|_| panic!("Unhandled out of memory error in breakOutputIntoPieces()"));

    // TODO: meta contents

    chunk.isolated_hash = c.generate_isolated_hash(chunk, worker_arena);
    chunk
        .flags
        .set(crate::chunk::Flags::IS_EXECUTABLE, is_executable);

    if c.options.source_maps != options::SourceMapOption::None {
        let can_have_shifts = matches!(
            chunk.intermediate_output,
            crate::chunk::IntermediateOutput::Pieces(_)
        );
        // Copy the `ParentRef` out (not `c.resolver()`) so the arg borrows the
        // local, not `c`, avoiding the split-borrow with
        // `c.generate_source_map_for_chunk(&mut self, …)`.
        let resolver = c.resolver.expect("resolver set in load()");
        chunk.output_source_map = c.generate_source_map_for_chunk(

View on GitHub (pinned to 8c5296ac45)