vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.82k stars 26.95k forks source link

15X Build Slowdown in the Latest NextJS Version #63315

Open MartinXPN opened 7 months ago

MartinXPN commented 7 months ago

Link to the code that reproduces this issue

https://github.com/MartinXPN/next-slow-build-reproduction

To Reproduce

# You can run `yarn build` instead to see the execution time
npm run build     # (~500s) This will build the app with the latest Next.js version
npm uninstall next && npm install next@13.4.19 && rm -rf .next
npm run build     # (~35s) This will build the app with the previous Next.js version

Current vs. Expected behavior

It currently takes ~15x longer to build a project with a large client-side component compared to the previous NextJS version. This REALLY hurts the developer experience! It should take way quicker to build the whole project and produce the production build.

For this small project, it took ~500s to build with the latest Next.js version, while it used to take only ~40 with the 13.4.9 version.

Using the latest version of NextJS actually resulted in a 20x build slowdown on one of my actual projects (not the reproduction above) making each build ~40 minutes instead of 2. Imagine how terrible it is to wait for 40 minutes for every minor change to hit production!

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:45:49 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6020
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 14.1.3
  eslint-config-next: 14.0.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A

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

Not sure, App Router, Dynamic imports (next/dynamic)

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

next build (local), Vercel (Deployed)

Additional context

I've also reproduced this with a large form using react-hook-form and zod.

There was a recent fix that was supposed to fix this issue but actually had no effect on my projects.

Screenshot 2024-03-15 at 1 13 18 PM Screenshot 2024-03-15 at 1 13 38 PM

This is the same project with the same dependencies (NextJS latest version VS 13.4.9). Imagine the pain of waiting 40 minutes every time you push to production (while it used to take only 2 minutes).

samvel1024 commented 7 months ago

I have the same issue after upgrading the library as well.

hrachgalstyan commented 7 months ago

I encountered the identical problem following the library upgrade too.

HakobjanyanHayk commented 7 months ago

Any updates on this?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

ngwallace commented 7 months ago

going through the same issue after upgarding the library

MartinXPN commented 6 months ago

Seems like the latest release of NextJS (14.2) fixed this issue partially. The project currently builds just 2X slower. Yet, deploying it to Vercel takes forever. The longest step seems to be the one that creates the serverless functions (used to be only a couple of seconds):

Created all serverless functions in: 16:32.559 (m:ss.mmm)