Docker Image Size Issue - April 9, 2026
Problem
Docker image grew significantly (~100MB+) and Next.js was crashing with:
MODULE_NOT_FOUND
path: '/app/node_modules/@next/env/package.json'
requestPath: '@next/env'Root Cause
Next.js standalone build (.next/standalone) doesn't include @next/env by default. This is a **runtime dependency** that Next.js requires but isn't part of the standalone output.
The Dockerfile had a fallback install:
RUN test -d node_modules/next/dist || npm install next@14.2.35 --no-audit --no-fundThis was triggering because node_modules/next/dist exists, but @next/env was missing. The fallback installed the **full Next.js package** including dev dependencies (~100MB+).
Fix
Updated the fallback to install both next and @next/env:
RUN test -d node_modules/next/dist || (npm install next@14.2.35 @next/env@14.2.35 --no-audit --no-fund)Why the Image Grew
- Fallback
npm installwas running (standalone artifacts incomplete) - This pulled in the full Next.js package with dev dependencies
- Dev dependencies include TypeScript, testing tools, build tools (~100MB+)
Verification
@next/envexists locally:.next/standalone/node_modules/@next/env/- Build completes successfully
- Dockerfile now handles the missing dependency
Next Steps
- Monitor deployment to ensure fix works
- Consider adding explicit
@next/envinstall to avoid fallback - Verify image size is reduced in production
Files Changed
Dockerfile- Added@next/envto fallback install