-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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:
- bcrypt 5.1.1 native binaries are not compatible with the Docker container's architecture
- Missing build tools during container startup prevent proper native module compilation
- 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
-
Clone the repository:
git clone https://github.com/code100x/cms.git cd cms -
Create Docker setup:
FROM node:18-bullseye-slim WORKDIR /app COPY . . RUN npm install -g pnpm RUN pnpm install CMD ["pnpm", "dev"]
-
Run container:
docker build -t cms-test . docker run -p 3000:3000 cms-test
- 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 bcryptOption 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 specificationsrc/lib/auth.ts- Authentication logic using bcryptsetup.sh- Docker setup script (if using option 2)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working