How to fix npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139 in npm

npmADVANCEDHIGHUpdated Dec 6, 2025· 195 views

Exit code 139 indicates SIGSEGV (segmentation fault), typically caused by native module binary incompatibilities. Rebuild native modules for your platform or use a compatible base image.

Quick fix

Fixes npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139

# Rebuild all native modules
npm rebuild

# Rebuild specific problematic package
npm rebuild bcrypt --build-from-source
npm rebuild node-sass --build-from-source
  1. Rebuild native modules for target platform
  2. Clean install from scratch
  3. Install build dependencies (Docker/Linux)
  4. Use glibc-based Docker image instead of Alpine
npm — error
# Rebuild all native modules
npm rebuild
# Rebuild specific problematic package
npm rebuild bcrypt --build-from-source
npm rebuild node-sass --build-from-source
npm ERR! code ELIFECYCLE
npm ERR! errno 139
npm ERR! Exit status 139

What this error means

Exit code 139 is calculated as 128 + 11, where 11 is the SIGSEGV (segmentation fault) signal. This error occurs when a process attempts to access memory it's not allowed to access—essentially, a crash at the native code level. In npm contexts, this almost always indicates a native module binary incompatibility. Packages with C++ bindings (like bcrypt, node-sass, sharp, or serialport) ship pre-compiled binaries for specific platforms. When these binaries don't match your system's architecture, libc version, or Node.js version, they crash with a segmentation fault.

Typical symptoms

  • Segmentation fault message during npm install or build
  • Works locally but crashes in Docker container
  • Error occurs specifically with native modules (bcrypt, node-sass, etc.)
  • Copying node_modules between different OS causes crashes
  • Works on macOS/Windows but fails on Linux (Alpine)
  • Crashes during webpack optimization or compilation

Common causes

  1. Native module pre-compiled binaries incompatible with target platform
  2. Alpine Linux musl libc incompatible with glibc-compiled binaries
  3. Node.js version mismatch with compiled native modules
  4. Architecture mismatch (x64 vs arm64)
  5. Docker container using different OS than where node_modules was created
  6. Memory corruption from incompatible shared libraries

How to fix "npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139"

1Rebuild native modules for target platform

Force rebuild native modules from source:

bash
# Rebuild all native modules
npm rebuild

# Rebuild specific problematic package
npm rebuild bcrypt --build-from-source
npm rebuild node-sass --build-from-source
2Clean install from scratch

Remove all cached binaries and reinstall:

bash
# Remove everything
rm -rf node_modules package-lock.json

# Clear npm cache
npm cache clean --force

# Reinstall
npm install
3Install build dependencies (Docker/Linux)

Native modules need build tools to compile from source:

Alpine Linux:

dockerfile
RUN apk add --no-cache python3 make g++ gcc

Debian/Ubuntu:

dockerfile
RUN apt-get update && apt-get install -y build-essential python3
4Use glibc-based Docker image instead of Alpine

Alpine uses musl libc which causes more segfaults:

dockerfile
# Instead of:
FROM node:18-alpine

# Use:
FROM node:18-slim
# or
FROM node:18-bullseye

glibc-based images have better native module compatibility.

5Match Node.js version with module requirements

Native modules are compiled for specific Node versions:

bash
# Check what Node version the module expects
npm view bcrypt engines

# Switch to compatible version
nvm install 18
nvm use 18

# Reinstall after switching
rm -rf node_modules && npm install
6Install node_modules inside Docker

Don't copy host node_modules into containers:

dockerfile
# Copy only package files first
COPY package*.json ./

# Install inside container
RUN npm ci

# Then copy source code
COPY . .

This ensures native modules are compiled for the container's architecture.

7Configure WSL2 for compatibility (Windows)

Some older container images need vsyscall emulation:

Create %USERPROFILE%\.wslconfig:

ini
[wsl2]
kernelCommandLine = vsyscall=emulate

Restart WSL: wsl --shutdown

Advanced notes

For debugging segfaults, use the segfault-handler module to get stack traces:

bash
npm install segfault-handler

Add to your entry file:

javascript
const SegfaultHandler = require('segfault-handler');
SegfaultHandler.registerHandler('crash.log');

For bcrypt specifically, consider using bcryptjs (pure JavaScript) in environments where native compilation is problematic. It's slower but avoids native module issues entirely.

Sharp (image processing) and canvas packages are frequent culprits. Both have specific installation instructions for different platforms in their documentation.

Frequently asked questions

What does "npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139" mean?
Exit code 139 is calculated as 128 + 11, where 11 is the SIGSEGV (segmentation fault) signal. This error occurs when a process attempts to access memory it's not allowed to access—essentially, a crash at the native code level. In npm contexts, this almost always indicates a native module binary incompatibility.
How do I fix "npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139"?
Exit code 139 indicates SIGSEGV (segmentation fault), typically caused by native module binary incompatibilities. Rebuild native modules for your platform or use a compatible base image.
What causes "npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139"?
Native module pre-compiled binaries incompatible with target platform Alpine Linux musl libc incompatible with glibc-compiled binaries Node.js version mismatch with compiled native modules
Is the "npm ERR! code ELIFECYCLE npm ERR! errno 139 npm ERR! Exit status 139" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading