Articles in this section

Fixing npm ERR! Exit status 137 during deployments

If your deployment fails during the build phase with an Exit status 137 (or Killed error Command failed with exit code 137 if using Yarn), it indicates that your build process has run out of memory.

Error 137 is the standard Linux exit code for an Out-Of-Memory (OOM) kill. The operating system terminated your npm or yarn process because it attempted to consume more RAM than your Upsun build container currently allows.

This is a common issue with heavy front-end builds, particularly those using Webpack, React, Next.js, or Angular.

Cause

When you push code to Upsun, your application is compiled inside an isolated build container. If your Node.js build (npm run build or yarn build) requires more memory than the container is allocated, the platform's OOM killer will forcefully stop the process to protect the host infrastructure.

Resolution

There are three main ways to resolve this issue on Upsun: restricting Node's memory allocation, increasing your build resources, or optimizing your package manager.

Option 1: Limit Node.js Memory Usage (The "Incantation")

By default, Node.js can be highly aggressive with memory allocation during heavy compilation tasks. You can explicitly cap the memory Node is allowed to use by setting the NODE_OPTIONS environment variable.

Add the following to your application definition in .upsun/config.yaml:

YAML

 
applications:
    myapp:
        # ... your existing app config ...
        variables:
            env:
                # Limits Node's V8 heap size to ~1.5GB to prevent it from hitting the container limit
                NODE_OPTIONS: --max_old_space_size=1536 

Note: Depending on how heavy your build is, restricting the memory might cause the build to fail internally within Webpack instead of being killed by the OS. If it still fails, proceed to Option 2.

Option 2: Increase Project Build Resources (The Upsun Way)

One of the major advantages of Upsun is flexible resource allocation. If limiting Node's memory causes the build to fail, or if your application genuinely requires a massive amount of RAM to compile, you can easily increase the memory available to your build container.

To increase your build resources:

  1. Log in to the Upsun Console.

  2. Navigate to your project and select Settings.

  3. Under the Resources or Build Resources section, allocate more CPU and RAM to the build phase.

  4. Trigger a new deployment to compile your application with the upgraded resources.

Option 3: Optimize Your Package Manager

If the OOM kill is happening during the npm install phase rather than the build phase, it is likely because npm install is creating a massive dependency tree in memory.

  • Use npm ci: Update the build hook in your .upsun/config.yaml to use npm ci instead of npm install. This command bypasses a lot of memory-heavy dependency resolution by installing exactly what is in your package-lock.json.

  • Try Yarn: Some users report that Yarn handles memory garbage collection slightly better during installations. If feasible, switching your build hook to use yarn install and yarn build may keep you just under the memory limit.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.