Skip to content

Turbopack Docker build significantly slower than Webpack (~6.8x) #88174

@hmaesta

Description

@hmaesta

When running npm run build natively with Turbopack, the build time is significantly faster compared to Webpack (~1s vs. ~10s); however, the opposite occurs when building a Docker image.

Link to the code that reproduces this issue

https://github.com/hmaesta/nextjs-turbopack-docker

To Reproduce

You can reproduce by cloning this repository or following these steps with create-next-app:

1. Initiate a minimal project

npx create-next-app@latest docker-experiment \
  --js --no-tailwind --no-react-compiler --no-linter \
  --empty --use-npm --src-dir --app --import-alias "@/*"

(As of Jan 6 2026, using "canary" instead of "latest" presented similar results)

2. Go to the project

cd docker-experiment

3. Create a minimal Dockerfile

curl -fsSL "https://raw.githubusercontent.com/hmaesta/nextjs-turbopack-docker/refs/heads/main/Dockerfile" -o Dockerfile

... or copy the contents of Dockerfile

4. Add output: 'standalone' to Next config

perl -i -pe 'print "  output: \x27standalone\x27,\n" if $. == 3' next.config.mjs

... or edit next.config.mjs manually

5. Build the image using Turbopack

docker build . -t docker-experiment-turbopack

Using a M2 Pro MacBook, the npm run build step took ~76s. (Docker is set to max cores and memory.)

Out of curiosity, running time npm run build natively - outside of the Docker context - takes less than 2s.

6. Move to Webpack

Now, let's move to Webpack by adding --webpack to package.json commands:

perl -i -pe '
  s/"dev":\s*"next dev"/"dev": "next dev --webpack"/;
  s/"build":\s*"next build"/"build": "next build --webpack"/;
' package.json

... or edit package.json manually

7. Build the image using Webpack

docker build . -t docker-experiment-webpack

This step takes ~11s.

Running time npm run build natively takes almost 10s; really close to the Docker results.

In a large codebase, these results are exponential in scale. In my daily job, Webpack takes ~90 seconds, compared to ~1,000 seconds (16 minutes) with Turbopack.

Current vs. Expected behavior

  • The build step shouldn't be so slow compared to the time it takes to run natively (without Docker)
  • Ideally, it should be faster than Webpack

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:34 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 25.2.1
  npm: 11.7.0
  Yarn: 1.22.22
  pnpm: 10.18.2
Relevant Packages:
  next: 16.1.0 // ← This is incorrect; I have "16.1.1" in my package.json
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.8.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

The same issue has also been reported by #77721 (comment)

Maybe related to #77624 and #82625

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurbopackRelated to Turbopack with Next.js.linear: turbopackConfirmed issue that is tracked by the Turbopack team.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions