invalid ELF header 📦 npm

Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

A native module compiled for macOS/Windows is being loaded on Linux.

Seen on: npm

Meaning

.node binaries are platform-specific. Copying node_modules into a Docker image or server from another OS causes it.

Common causes

  • node_modules copied from the host into the container
  • Shared volume between host and container

⚡ Quick fix

  1. Exclude node_modules via .dockerignore and run npm ci in the image
  2. Rebuild: npm rebuild

Detailed fix by platform

Docker

  1. bash
    COPY package*.json ./
    RUN npm ci
    COPY . .

How to diagnose

  1. Build — Where was node_modules created?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.