Skip to content

bug: [Docker] bcrypt 5.1.1 native binary compatibility issue #1877

@NameawaShinderu

Description

@NameawaShinderu

Environment

  • OS: Linux (Docker container)
  • Node.js Version: 18.x
  • Container Base: node:18-bullseye-slim
  • Package Manager: pnpm
  • bcrypt Version: 5.1.1 (problematic), 6.0.0 (working)

Problem Description

When running the CMS in a Docker container, the application fails to start due to missing bcrypt native binaries. This occurs specifically with bcrypt version 5.1.1.

Error Details

Error: Cannot find module '/app/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'
Require stack:
- /app/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
- /app/.next/server/app/page.js

Full Error Stack:

⨯ Error: Cannot find module '/app/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at Object.<anonymous> (/app/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js:6:16)

Root Cause

The issue occurs because:

  1. bcrypt 5.1.1 native binaries are not compatible with the Docker container's architecture
  2. Missing build tools during container startup prevent proper native module compilation
  3. pnpm's handling of native modules in containerized environments has compatibility issues

Impact

  • ❌ Application fails to start in Docker environments
  • ❌ Development workflow broken for containerized setups
  • ❌ Deployment to container platforms (K8s, Docker Swarm) fails
  • ❌ NextAuth.js authentication system non-functional

Reproduction Steps

  1. Clone the repository:

    git clone https://github.com/code100x/cms.git
    cd cms
  2. Create Docker setup:

    FROM node:18-bullseye-slim
    WORKDIR /app
    COPY . .
    RUN npm install -g pnpm
    RUN pnpm install
    CMD ["pnpm", "dev"]
  3. Run container:

    docker build -t cms-test .
    docker run -p 3000:3000 cms-test
Image
  1. Observe error in container logs when accessing the application

Current Workaround

Temporary Fix (inside running container):

# Access container
docker exec -it <container_id> bash

# Remove and reinstall bcrypt
pnpm remove bcrypt && pnpm add bcrypt

# This automatically upgrades to bcrypt 6.0.0
# Restart container
exit
docker restart <container_id>

Proposed Solution

Option 1: Update package.json

{
  "dependencies": {
    "bcrypt": "^6.0.0"
  }
}

Option 2: Add Docker-specific setup script

# In Dockerfile or docker-compose command
RUN pnpm install && pnpm rebuild bcrypt

Option 3: Switch to bcryptjs (pure JavaScript)

{
  "dependencies": {
    "bcryptjs": "^2.4.3"
  }
}

Testing

I have verified that upgrading to bcrypt 6.0.0 resolves the issue:

  • ✅ Container starts successfully
  • ✅ Application loads without errors
  • ✅ Authentication system works properly
  • ✅ No performance degradation observed

Additional Context

  • This issue affects all containerized deployments
  • Problem is specific to bcrypt's native binary compilation
  • bcrypt 6.0.0 includes improved container compatibility
  • Issue reproduced on multiple container platforms (Docker, Podman)

Files Affected

  • package.json - bcrypt version specification
  • src/lib/auth.ts - Authentication logic using bcrypt
  • setup.sh - Docker setup script (if using option 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions