nextjs - 💡(How to fix) Fix Turbopack Docker build significantly slower than Webpack (~6.8x) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#88171Fetched 2026-04-08 02:05:28
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Code Example

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

---

cd docker-experiment

---

curl -fsSL "https://gist.githubusercontent.com/hmaesta/b43737bd40d419767c1d8f5632fb6de8/raw/d9f83c3dca1300caf210329814c070309ca135c3/Dockerfile" -o Dockerfile

---

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

---

docker build . -t docker-experiment-turbopack

---

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

---

docker build . -t docker-experiment-webpack

---

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
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vercel/next.js/tree/canary/packages/create-next-app

To Reproduce

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

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 "@/*"

<sup>(As of Jan 6 2026, using "canary" instead of "latest" showed similar results)</sup>

2. Go to the project

cd docker-experiment

3. Create a minimal Dockerfile

curl -fsSL "https://gist.githubusercontent.com/hmaesta/b43737bd40d419767c1d8f5632fb6de8/raw/d9f83c3dca1300caf210329814c070309ca135c3/Dockerfile" -o Dockerfile

<sup>... or copy the contents of https://gist.github.com/hmaesta/b43737bd40d419767c1d8f5632fb6de8</sup>

4. Add output: 'standalone' to Next config

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

<sup>... or edit next.config.mjs manually</sup>

5. Building the image using Turbopack

docker build . -t docker-experiment-turbopack

Using a M2 Pro MacBook, the npm run build step took ~76s.

(For curiosity, running time npm run build natively - directly in CLI, outside of the Docker context - takes less than 2s.)

Now, let's build the image with Webpack instead of Turbopack...

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

<sup>... or <a href="https://nextjs.org/docs/app/api-reference/turbopack#using-webpack-instead">edit package.json manually</a></sup>

7. Building the image using Webpack

docker build . -t docker-experiment-webpack

This step takes ~11s.

(This time, running time npm run build natively - directly in CLI - takes almost 10s; really close to the Docker results.)


In a large codebase, these results are exponential. In my daily job, Webpack takes ~90 seconds vs ~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

This has also been reported by https://github.com/vercel/next.js/discussions/77721#discussioncomment-14778541 (hidden by default in the large amount of comments)

extent analysis

TL;DR

The build time discrepancy between Turbopack and Webpack when building a Docker image can be addressed by investigating the differences in build processes and optimizing the Turbopack configuration for Docker environments.

Guidance

  1. Investigate Docker build process: Compare the build processes of Turbopack and Webpack within the Docker environment to identify potential bottlenecks or inefficiencies.
  2. Optimize Turbopack configuration: Review the Turbopack configuration options to ensure they are optimized for the Docker build process, considering factors like caching, parallel processing, and output settings.
  3. Compare native and Docker build times: Continue to monitor and compare build times between native and Docker environments to understand the performance differences and identify areas for improvement.
  4. Explore caching mechanisms: Consider implementing caching mechanisms, such as Docker layer caching, to improve build times for subsequent builds.
  5. Verify Next.js version: Ensure that the correct version of Next.js (16.1.1) is being used, as specified in the package.json file, to rule out any version-related issues.

Example

No code snippet is provided as the issue is more related to the build process and configuration rather than a specific code problem.

Notes

The issue seems to be specific to the Docker build process with Turbopack, and the cause may be related to how Turbopack handles builds in a containerized environment. Further investigation into the build process and configuration is necessary to identify the root cause.

Recommendation

Apply workaround: Investigate and optimize the Turbopack configuration for the Docker environment, as the issue seems to be related to the build process rather than a version-specific problem. This approach allows for a more targeted solution without relying on version upgrades.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Turbopack Docker build significantly slower than Webpack (~6.8x) [1 comments, 2 participants]