Skip to content

Frontend app builds can fail with Node.js heap out-of-memory #471

Description

@aakvatech

Problem

Pilot can fail when installing Frappe apps with large standalone frontends because the frontend yarn build process runs with Node.js's default heap limit.

This was encountered while installing frappe/crm. Dependency installation succeeds and the Vite build progresses normally, transforming approximately 2,900 modules, but fails during chunk rendering:

FATAL ERROR: Ineffective mark-compacts near heap limit
Allocation failed - JavaScript heap out of memory

Aborted (core dumped)
error Command failed with exit code 134.

Pilot then rolls back the app installation.

Environment

Observed on:

  • Ubuntu server
  • 8 GB RAM
  • 4 GB swap
  • CRM frontend built through Pilot

The default Node heap limit was approximately:

2240 MB

With:

NODE_OPTIONS="--max-old-space-size=4096"

the heap limit increased to approximately:

4288 MB

This indicates that the failure is caused by the Node/V8 heap ceiling rather than lack of total system memory.

Pilot Build Path

The failure occurs in pilot/managers/python_assets.py when Pilot builds a standalone frontend:

run_command(
    [get_yarn_bin(), "build"],
    cwd=app.path / frontend_dir,
    stream_output=True,
)

The frontend build does not explicitly set an appropriate Node heap size.

Expected Behaviour

Pilot should allocate enough Node heap for large frontend builds when sufficient system memory is available, without requiring administrators to manually export NODE_OPTIONS.

Suggested Approach

Avoid hardcoding a fixed value such as 4096 MB.

Instead, Pilot should calculate a safe heap size based on currently available system memory, for example:

Node heap = available memory × 60%

with sensible limits such as:

minimum: 2048 MB
maximum: 6144 MB

Example logic:

heap_mb = int(available_memory_mb * 0.60)
heap_mb = max(2048, heap_mb)
heap_mb = min(heap_mb, 6144)

Pilot could then pass:

NODE_OPTIONS=--max-old-space-size=<calculated value>

to frontend build processes.

There should also be an administrator override, for example:

PILOT_NODE_MAX_OLD_SPACE_SIZE=4096

If the override is configured, Pilot should use it instead of the automatically calculated value.

Acceptance Criteria

  • Frontend builds receive a calculated Node heap size based on available memory.
  • The heap size uses sensible minimum and maximum limits.
  • Administrators can override the calculated value.
  • Existing environment variables are preserved.
  • Normal Frappe/ERPNext builds continue working unchanged.
  • Large frontend apps such as frappe/crm can complete their production build on adequately sized servers.
  • Automated tests cover heap calculation, override behaviour, and environment propagation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions