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.
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.
Force rebuild native modules from source:
# Rebuild all native modules
npm rebuild
# Rebuild specific problematic package
npm rebuild bcrypt --build-from-source
npm rebuild node-sass --build-from-sourceRemove all cached binaries and reinstall:
# Remove everything
rm -rf node_modules package-lock.json
# Clear npm cache
npm cache clean --force
# Reinstall
npm installNative modules need build tools to compile from source:
Alpine Linux:
RUN apk add --no-cache python3 make g++ gccDebian/Ubuntu:
RUN apt-get update && apt-get install -y build-essential python3Alpine uses musl libc which causes more segfaults:
# Instead of:
FROM node:18-alpine
# Use:
FROM node:18-slim
# or
FROM node:18-bullseyeglibc-based images have better native module compatibility.
Native modules are compiled for specific Node versions:
# 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 installDon't copy host node_modules into containers:
# 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.
Some older container images need vsyscall emulation:
Create %USERPROFILE%\.wslconfig:
[wsl2]
kernelCommandLine = vsyscall=emulateRestart WSL: wsl --shutdown
For debugging segfaults, use the segfault-handler module to get stack traces:
npm install segfault-handlerAdd to your entry file:
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.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error