Skip to content

Commit 5df1f0d

Browse files
committed
fix: Fix production Dockerfile for ES modules
🔧 Production Docker Fix ## Issue Fixed: - Production container failing with 'Cannot find module /app/dist/main.js' - ES modules not properly handled in production build ## Solution: - Simplified Dockerfile.prod to single-stage build - Install all dependencies for build, then prune dev dependencies - Direct ES module execution: 'node dist/main.js' - Proper file copying and permissions ## Key Changes: - Removed complex multi-stage build - Added npm prune --production after build - Direct node execution instead of npm script - Maintained all necessary system dependencies This fixes the production deployment issue where the NestJS application wasn't starting due to ES module configuration.
1 parent f72083f commit 5df1f0d

1 file changed

Lines changed: 6 additions & 31 deletions

File tree

nodebook-base/Dockerfile.prod

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# NodeBook NestJS Production Dockerfile
2-
# Multi-stage build for optimized production image
3-
4-
# Stage 1: Base image with Node.js 20 LTS
5-
FROM node:20-alpine AS base
2+
FROM node:20-alpine
63

74
# Install system dependencies for libp2p and crypto
85
RUN apk add --no-cache \
@@ -18,13 +15,7 @@ WORKDIR /app
1815
# Copy package files
1916
COPY package*.json ./
2017

21-
# Install dependencies
22-
RUN npm ci --only=production && npm cache clean --force
23-
24-
# Stage 2: Development dependencies
25-
FROM base AS development
26-
27-
# Install development dependencies
18+
# Install all dependencies (including dev dependencies for build)
2819
RUN npm ci
2920

3021
# Copy source code
@@ -33,24 +24,8 @@ COPY . .
3324
# Build NestJS application
3425
RUN npm run build
3526

36-
# Create necessary directories with proper permissions
37-
RUN mkdir -p user_data logs media data && \
38-
chmod -R 755 user_data logs media data
39-
40-
# Expose port
41-
EXPOSE 3000
42-
43-
# Health check
44-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
45-
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
46-
47-
# Start NestJS application
48-
CMD ["npm", "run", "start"]
49-
50-
# Stage 3: Production build
51-
FROM development AS production
52-
53-
# No additional steps needed - build was done in development stage
27+
# Remove dev dependencies to reduce image size
28+
RUN npm prune --production
5429

5530
# Create necessary directories with proper permissions
5631
RUN mkdir -p user_data logs media data && \
@@ -63,5 +38,5 @@ EXPOSE 3000
6338
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
6439
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
6540

66-
# Start NestJS application
67-
CMD ["npm", "run", "start"]
41+
# Start NestJS application (ES modules)
42+
CMD ["node", "dist/main.js"]

0 commit comments

Comments
 (0)