# npm error code 137 or Killed during npm install or npm run build: what it means

> Exit code 137 is 128 + 9: the process received SIGKILL, signal 9, which it cannot catch. During npm install or npm run build that is almost always the Linux out-of-memory killer, because the machine or the container's memory limit ran out. It is not Node's own heap limit, which prints FATAL ERROR ... JavaScript heap out of memory before it stops. Run fewer heavy steps at once, turn off production source maps, keep Node's heap below the container, or give the build more memory.

Source: https://livops.dev/en/guides/error-npm-exit-code-137-killed

By Livops team, the people who build and run Livops. Updated 4 December 2026.

One or more of these at the end of the log, with no stack trace and nothing from your own code just above them:

```text
Killed
npm error code 137
npm error signal SIGKILL
npm ERR! code 137
```

This page explains where 137 comes from, how to tell it apart from Node's own `JavaScript heap out of memory`, how to prove it was memory, and what to change, from the cheapest fix to buying more memory. Everything up to "On Livops" applies to any machine, CI runner or container.

## What does exit code 137 mean?

It is a signal, not an error code from your program. When a command is ended by signal *n*, the shell reports its status as 128 + *n*[1]. 137 − 128 = 9, and signal 9 is `SIGKILL`[2]. `SIGKILL` cannot be caught, blocked or ignored[2], so neither Node nor npm gets to run any code after it: no error message, no stack trace, no cleanup. That is why the log simply stops.

### Who sends SIGKILL during a build

Almost always the kernel's out-of-memory (OOM) killer:

- **In a container**, memory is capped by the cgroup's `memory.max`. If the cgroup's usage reaches that limit and can't be reduced, the OOM killer is invoked inside the cgroup[3]. Docker says the same: by default, if an out-of-memory error occurs, the kernel kills processes in the container[5].
- **On a whole machine**, when the kernel cannot find memory for its own work, it starts killing processes to free some[5].

In both cases the kernel sends the chosen process `SIGKILL`[4]. The limit counts the cgroup "and its descendants"[3]: npm, the shell it starts, Node, esbuild, a type checker running beside the bundler. They share one budget, and the kernel picks one of them to kill.

The other senders of `SIGKILL` are people and tools: a `kill -9`, a CI system cancelling a job, a supervisor ending a step that ran too long. Those leave no out-of-memory trace (see below), so check before you start cutting memory. `docker stop` is one of them: it sends `SIGTERM`, then `SIGKILL` once the grace period runs out[17], so an app that ignores `SIGTERM` exits with 137 too. The fix then is to stop cleanly on `SIGTERM`, not to add memory.

### What npm adds

npm runs a script through `/bin/sh` on Linux and macOS and `cmd.exe` on Windows[8]. When the script fails, npm's error report lists its exit `code`, and the `signal` when the process died from one[9]: that is `npm error code 137` or `npm error signal SIGKILL`, followed by `command failed` and the command. Newer npm writes these lines as `npm error`, older versions as `npm ERR!`[10]; the meaning is the same. A bare `Killed` line comes from outside Node and npm as well, since neither can print anything after `SIGKILL`.

## 137 or heap out of memory: which one is it?

They are two different ceilings, and the last lines of the log say which one was hit:

| The log ends with | What stopped the process | The ceiling that was reached |
| --- | --- | --- |
| `FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory` | Node itself, before exiting | V8's heap limit, set by `--max-old-space-size`[11] |
| `Killed`, code 137, `signal SIGKILL`, and no `FATAL ERROR` | The kernel, from outside | The memory of the container or the machine |

Node prints the first one itself when V8 reports that its heap is out of memory[12]; for that case see [JavaScript heap out of memory](https://livops.dev/en/guides/error-javascript-heap-out-of-memory), and for Next.js [heap out of memory during next build](https://livops.dev/en/guides/error-next-build-heap-out-of-memory).

The two are connected. Node's heap limit is a ceiling inside one process; the container's limit is a ceiling on everything in it. If Node is allowed a heap bigger than the memory the container can give, the kernel's limit is reached first, and what would have been a readable heap error becomes a bare 137. This is the usual way people get here: they raise `--max-old-space-size` past the container's memory to fix a heap error.

## How to confirm it was memory

- **A container you ran.** `docker inspect` reports `OOMKilled`: whether a process in the container was killed because it ran out of memory since the container last started[6].

  ```sh
  docker inspect my-build | grep OOMKilled
  ```

- **Kubernetes.** `kubectl get pod <pod>` shows `OOMKilled` as the container's last state when it was killed for memory[18].

  ```sh
  kubectl get pod my-pod -o yaml | grep -A3 lastState
  ```

- **The kernel log on the host.** `dmesg` prints the kernel ring buffer[7]. The OOM killer writes `Out of memory: Killed process <pid> (<name>)` for the whole machine, and `Memory cgroup out of memory: Killed process ...` when a cgroup's limit was the cause[4].

  ```sh
  dmesg -T | grep -i "killed process"
  ```

- **From inside a cgroup v2 container.** `memory.events` counts `oom_kill`, the processes in the cgroup killed by an OOM killer, and `memory.peak` is the most memory the cgroup has used[3]. With cgroup v2 they are usually under `/sys/fs/cgroup`:

  ```sh
  cat /sys/fs/cgroup/memory.events /sys/fs/cgroup/memory.peak
  ```

On a hosted CI runner or a platform you usually cannot read the host's kernel log. Then the evidence is the shape of the log: 137 or `Killed`, no `FATAL ERROR`, at the step that uses the most memory, and a local run under the same limit (below) that fails the same way.

## Fixes, cheapest first

### 1. Don't run heavy steps at the same time

A build script that starts the type checker and the bundler together, or a monorepo tool that builds several packages in parallel, runs several Node processes inside one memory limit[3]. Run them one after another:

```json
{
  "scripts": {
    "build": "tsc --noEmit && vite build"
  }
}
```

The same holds for plugins that move work to a separate process. webpack's guide suggests `fork-ts-checker-webpack-plugin` to run type checking in its own process[15]: that makes the build faster, but the extra process still counts against the same container.

### 2. Turn off production source maps

Source maps cost memory and time while they are generated.

- **webpack:** its guide says source maps are "really expensive"[15]. `devtool: false` emits none, and the docs call it a good option to start with in production[14].
- **Create React App:** `GENERATE_SOURCEMAP=false` stops source maps in the production build, and the docs name this as a fix for out-of-memory problems on smaller machines[13].
- **Vite:** `build.sourcemap` is `false` by default[16]; if your config turns it on, try the build without it.
- **Next.js:** see [heap out of memory during next build](https://livops.dev/en/guides/error-next-build-heap-out-of-memory).

### 3. Give Node a heap limit that fits inside the container

Set the heap below the memory the build really has, so that Node, not the kernel, reaches its limit first. Node's docs suggest 1536 MiB on a machine with 2 GiB, to leave memory for other uses[11]:

```sh
NODE_OPTIONS=--max-old-space-size=1536 npm run build
```

This does not make the build need less. It changes how it fails: if the Node heap is the problem, you now get `JavaScript heap out of memory` naming the step, instead of a silent 137. If 137 still happens with the heap capped, the memory is going somewhere other than one Node heap: parallel processes, native tools, or `npm install` itself.

### 4. When `npm install` is the step that dies

Look at what the install was doing when it stopped. If it was compiling a native module from source, see [node-gyp rebuild failed](https://livops.dev/en/guides/error-node-gyp-rebuild-failed): a package with a prebuilt binary skips the compile entirely. Keep the install and the build as separate steps, so the peak is one or the other, not both.

### 5. When it truly needs more memory

If the build's peak is still above the limit after the steps above, raise the limit. Measure the peak first (`memory.peak` above[3]), then:

- **Docker:** `-m` / `--memory` is the most memory the container can use[5]. If `--memory` is set and `--memory-swap` is not, the container can also use as much swap as its memory setting, when the host has swap[5]: a build that swaps survives, slowly.
- **CI:** choose a larger runner.
- **A platform:** a bigger build or plan; see the Livops section below.

## How to reproduce it locally

Run the build under the same limit as the server. On a laptop with plenty of memory it passes; inside a container with `-m` it fails the same way:

```sh
docker run --rm -m 2g -v "$PWD":/app -w /app node:22 \
  sh -c "npm ci && npm run build"
echo $?
```

`137` there confirms the diagnosis. Then try the fixes one at a time until it passes with room to spare.

## On Livops

- **The build's memory is in the first line of the log.** The build log starts with `Build server: <region> · <n> cores, <memory>`: that is the ceiling for one build step. For a project built from its own `Dockerfile`, the line states that build's ceiling.
- **Node's heap is set to fit it.** For a framework build (not your own `Dockerfile`), every install and build step runs with `NODE_OPTIONS=--max-old-space-size` set to three quarters of the build container's memory, leaving the rest for esbuild, native modules and the shell. A Node process that outgrows the build then reports `JavaScript heap out of memory` and names the step, instead of being killed with nothing printed. If you set `NODE_OPTIONS` in **Variables**, Livops leaves it alone; keep your value below the ceiling the first line states. In your own `Dockerfile`, Livops sets nothing: put it on the `RUN` line yourself.
- **A Tip when it runs out.** When a build step is killed with exit status 137, or prints `JavaScript heap out of memory`, the log ends with: `Tip: the build ran out of memory. For a Node build set NODE_OPTIONS=--max-old-space-size=2048 in the variables and turn off source maps in production (GENERATE_SOURCEMAP=false, productionBrowserSourceMaps: false); if it still does not fit, write to us for a bigger build.` The deploy fails at that step, and the previous version keeps running.
- **A running app that hits 137.** An app that uses more memory than its plan allows is stopped, and the log says `Killed` or exit code 137. Choose a bigger memory tier in the settings or make the app use less. The tiers are 256, 512, 1024, 2048, 3072 and 4096 MiB; `memory` in `livops.json` sets it when the project is created, and the settings change it after that. A Node app's heap limit is not set for you at run time: add `NODE_OPTIONS` in **Variables**, below the tier. Two causes look the same: the app needs more than the tier (a large model, a big cache, several workers), or it leaks. Watch memory after a restart: flat near the limit from the start means it needs more; a steady climb until the kill means a leak, and a bigger tier only makes the cycle longer.
- **The assistant offers the bigger tier.** Write "out of memory" or "exit code 137" about a project in the cabinet or in Telegram, and the assistant offers the next memory size as a button.
- **See the memory over time.** Through the Livops MCP server, `get_metrics` returns a service's CPU, memory and traffic for 1 hour, 24 hours or 7 days, enough to tell a steady climb from one spike.

```json
{
  "memory": 1024
}
```

More in the docs: [The build ran out of memory](https://livops.dev/en/docs/error-build#build-memory), [Out of memory](https://livops.dev/en/docs/error-start#out-of-memory) and [Frameworks and livops.json](https://livops.dev/en/docs/frameworks).

## Questions

**What does exit code 137 mean?**

128 + 9. A shell reports 128 plus the signal number when a command is ended by a signal, and signal 9 is SIGKILL. SIGKILL cannot be caught, so the process had no chance to print anything. During a build it is almost always the out-of-memory killer.

**Is exit code 137 the same as JavaScript heap out of memory?**

No. Heap out of memory is Node stopping itself because V8's heap reached its limit, and it prints FATAL ERROR first. Exit code 137 is the kernel killing the process from outside because the machine or container ran out, with no message from Node. A heap limit set above the container's memory turns the first into the second.

**How do I prove it was memory and not something else?**

For a Docker container, docker inspect shows OOMKilled true. On the host, the kernel log has a line like Out of memory: Killed process, or Memory cgroup out of memory: Killed process for a container limit. In a cgroup v2 container, the oom_kill count in memory.events goes up. A cancelled CI job or a kill -9 also gives 137, without those traces.

**Is exit code 137 always out of memory?**

No. Anything that sends SIGKILL gives 137: kill -9, a cancelled CI job, or docker stop when the app ignores SIGTERM and the grace period runs out. Check OOMKilled in docker inspect, or in Kubernetes the pod's last state, before you tune memory.

**Will adding swap fix it?**

It can keep the build alive, slower. Docker lets a container with a memory limit use as much swap as its memory setting when the host has swap configured and memory-swap is not set. Many CI runners and platforms have no swap at all, so the reliable fixes are using less memory or getting more.

**Why does the build pass on my laptop and fail in CI or Docker?**

Your laptop has more memory than the runner or the container's limit, and nothing kills the build there. Run the build locally under the same limit with docker run -m to see the 137 on your machine, then cut what the build holds.

**How much memory does a Livops build get?**

The first line of the build log says it: Build server, the region, the cores and the memory. For a framework build Livops sets Node's heap to three quarters of that, unless you set NODE_OPTIONS yourself, so a Node process that outgrows it usually stops with heap out of memory instead of a bare 137. If it still does not fit, write to Livops for a bigger build.

## Sources

1. [bash(1) — Linux manual page (Simple Commands, exit status)](https://man7.org/linux/man-pages/man1/bash.1.html). Checked 3 December 2026.
2. [signal(7) — Linux manual page](https://man7.org/linux/man-pages/man7/signal.7.html). Checked 3 December 2026.
3. [Linux kernel docs — Control Group v2 (memory controller)](https://docs.kernel.org/admin-guide/cgroup-v2.html). Checked 3 December 2026.
4. [Linux source — mm/oom_kill.c](https://raw.githubusercontent.com/torvalds/linux/master/mm/oom_kill.c). Checked 3 December 2026.
5. [Docker docs — Resource constraints](https://docs.docker.com/engine/containers/resource_constraints/). Checked 3 December 2026.
6. [Docker Engine API — ContainerState (moby api/swagger.yaml)](https://raw.githubusercontent.com/moby/moby/master/api/swagger.yaml). Checked 3 December 2026.
7. [dmesg(1) — Linux manual page](https://man7.org/linux/man-pages/man1/dmesg.1.html). Checked 3 December 2026.
8. [npm docs — npm run-script](https://docs.npmjs.com/cli/v10/commands/npm-run-script). Checked 3 December 2026.
9. [npm CLI source — lib/utils/error-message.js](https://raw.githubusercontent.com/npm/cli/latest/lib/utils/error-message.js). Checked 3 December 2026.
10. [npm CLI — pull request 7414, log prefixes use the level name](https://github.com/npm/cli/pull/7414). Checked 3 December 2026.
11. [Node.js docs — Command-line API](https://nodejs.org/api/cli.html). Checked 3 December 2026.
12. [Node.js source — src/node_errors.cc](https://raw.githubusercontent.com/nodejs/node/main/src/node_errors.cc). Checked 3 December 2026.
13. [Create React App — Advanced configuration](https://create-react-app.dev/docs/advanced-configuration/). Checked 3 December 2026.
14. [webpack — devtool](https://webpack.js.org/configuration/devtool/). Checked 3 December 2026.
15. [webpack — Build performance](https://webpack.js.org/guides/build-performance/). Checked 3 December 2026.
16. [Vite — Build options](https://vite.dev/config/build-options). Checked 3 December 2026.
17. [Docker docs — docker container stop](https://docs.docker.com/reference/cli/docker/container/stop/). Checked 4 December 2026.
18. [Kubernetes — Assign Memory Resources to Containers and Pods](https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/). Checked 4 December 2026.
