ATOM Documentation

← Back to App

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-fund

This 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

  1. Fallback npm install was running (standalone artifacts incomplete)
  2. This pulled in the full Next.js package with dev dependencies
  3. Dev dependencies include TypeScript, testing tools, build tools (~100MB+)

Verification

  • @next/env exists locally: .next/standalone/node_modules/@next/env/
  • Build completes successfully
  • Dockerfile now handles the missing dependency

Next Steps

  1. Monitor deployment to ensure fix works
  2. Consider adding explicit @next/env install to avoid fallback
  3. Verify image size is reduced in production

Files Changed

  • Dockerfile - Added @next/env to fallback install