How to fix npm ERR! Error: Cannot find module '/app/node_modules/package/build/Release/module.node' in npm
This error occurs when Node.js tries to load a native addon compiled for glibc on Alpine Linux (which uses musl). The fix involves rebuilding native modules with Alpine's build tools or switching to a glibc-based Docker image.
Quick fix
Fixes npm ERR! Error: Cannot find module '/app/node_modules/package/build/Release/module.node'
npm rebuild- Try rebuilding native modules locally
- Clean and reinstall dependencies
- Install build dependencies in Docker (if using Alpine)
- Use multi-stage Docker build (recommended for production)
npm rebuildnpm ERR! Error: Cannot find module '/app/node_modules/package/build/Release/module.node'
What this error means
This error occurs when Node.js tries to load a native addon (compiled C++ module) at runtime, but the .node binary file doesn't exist in the expected location. Native modules are compiled during npm install using node-gyp, which invokes the system's C++ compiler to build platform-specific binaries. The missing file indicates either that the compilation failed silently, the module wasn't compiled for your system architecture, or—most commonly in Docker environments—the module was compiled for a different C standard library (glibc on your development machine vs musl on Alpine Linux containers). This mismatch is particularly problematic because native binaries are not portable across different libc implementations; a binary compiled against glibc will fail to load on a musl system, and vice versa.
Typical symptoms
- Error occurs at application startup or when requiring a specific package, not during npm install
- Running locally works fine but fails in Docker containers (especially Alpine-based images)
- The build/Release directory exists but is empty or contains only partial files
- Application works on Ubuntu/Debian Docker images but fails on Alpine Linux
- Seeing related errors like 'error loading shared library ld-linux-x86-64.so.2' or 'symbol not found'
Common causes
- Using Alpine Linux (musl libc) in Docker while dependencies were compiled on glibc systems (macOS, Ubuntu, Windows)
- Build dependencies (gcc, g++, make, python) not installed in Docker image when compiling native modules
- The npm install process was interrupted before native module compilation finished
- node-gyp compilation failed silently, leaving an incomplete or missing .node file
- Package was pre-built for a different CPU architecture (e.g., x86 vs ARM) than your current system
- Using pre-built native binaries from node_modules in a different environment than where they were compiled
How to fix "npm ERR! Error: Cannot find module '/app/node_modules/package/build/Release/module.node'"
First, attempt to rebuild the native modules in your current environment:
npm rebuildIf targeting a specific problematic package:
npm rebuild package-name --build-from-sourceIf this succeeds, the issue may have been incomplete compilation. If it still fails, the root cause is likely environmental mismatch (Docker-related).
Delete cached modules and reinstall from scratch:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installOr use the more reliable clean-install command:
npm ciThis ensures npm doesn't use cached prebuilt binaries.
If running in a Docker container with Alpine Linux, the C compiler toolchain isn't included by default. Add build tools before installing dependencies:
FROM node:alpine
# Install build dependencies
RUN apk add --no-cache python3 make g++
WORKDIR /app
COPY package*.json ./
# Now npm install will rebuild native modules against musl
RUN npm install
COPY . .
CMD ["node", "index.js"]Use --virtual to tag and later remove build dependencies:
RUN apk add --no-cache --virtual .gyp python3 make g++ \
&& npm install \
&& apk del .gypBuild native modules in one stage with full build tools, then copy only the compiled binaries to a final minimal image:
# Builder stage - includes compilation tools
FROM node:alpine as builder
RUN apk add --no-cache python3 make g++
WORKDIR /app
COPY package*.json ./
RUN npm install
# Final stage - minimal runtime image
FROM node:alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY . .
CMD ["node", "index.js"]This reduces final image size while ensuring native modules are compiled for musl.
The simplest solution is to avoid Alpine entirely and use the standard Node image based on Debian:
# Using Debian-based image instead of Alpine
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]Node images ending in -slim are still small (~200MB) but use glibc, matching most pre-built native module binaries.
Advanced notes
The core issue is that Alpine Linux uses musl libc while most development machines and pre-built binaries use glibc (GNU C Library). These are incompatible C standard library implementations—they have different ABIs, memory allocation strategies, and system call interfaces.
A .node file (native addon) compiled against glibc contains hardcoded references to glibc functions that don't exist in musl's namespace. When Node.js tries to dynamically load this binary into a musl-based process, the dynamic linker fails because it can't resolve those symbols.
The npm package detect-libc can programmatically identify which libc is present. For production deployments, Node.js official documentation recommends glibc-based images for Tier 1 support; musl on Alpine is experimental.
Some packages like node-sass and bcrypt are notorious for musl incompatibility; check GitHub issues before selecting Alpine for projects with heavy native dependencies.
Frequently asked questions
- What does "npm ERR! Error: Cannot find module '/app/node_modules/package/build/Re" mean?
- node binary file doesn't exist in the expected location. Native modules are compiled during npm install using node-gyp, which invokes the system's C++ compiler to build platform-specific binaries. The missing file indicates either that the compilation failed silently, the module wasn't compiled for your system architecture, or—most commonly in Docker environments—the module was compiled for a different C standard library (glibc on your development machine vs musl on Alpine Linux containers).
- How do I fix "npm ERR! Error: Cannot find module '/app/node_modules/package/build/Re"?
- This error occurs when Node.js tries to load a native addon compiled for glibc on Alpine Linux (which uses musl). The fix involves rebuilding native modules with Alpine's build tools or switching to a glibc-based Docker image.
- What causes "npm ERR! Error: Cannot find module '/app/node_modules/package/build/Re"?
- Using Alpine Linux (musl libc) in Docker while dependencies were compiled on glibc systems (macOS, Ubuntu, Windows) Build dependencies (gcc, g++, make, python) not installed in Docker image when compiling native modules The npm install process was interrupted before native module compilation finished
- Is the "npm ERR! Error: Cannot find module '/app/node_modules/package/build/Re" 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
- 📚npm Official Documentation
- 📖Docs: Node.js Docker(Official Docs)
- 🐙GitHub: docker-node(GitHub)
- 💬SO: Node.js on Alpine(Stack Overflow)