Solving slow compilation in dev mode for Next.js
Alex

Alex @asmyshlyaev177

About: Just another IT guy, 5+ years of coding on Frontend, Follow me on GitHub , appreciate it.

Location:
void 0
Joined:
Jun 27, 2019

Solving slow compilation in dev mode for Next.js

Publish Date: Nov 8 '24
5 1

Noticed that Next.js dev server is really slow, annoying that it can't precompile pages in the background.
There is a discussion about it.

Ways to make it faster

Turbopack

Can use turbopack, can run it with next dev --turbo, downsides that if you use some fine tweaks for Webpack, not everything works correctly with turbopack (at least for v14).

Upgrade to Next.js v15

v15 is faster by default, some common issues were solved. There is a codemod that will do most of the things for you in a few seconds.
Still, requires some effort.

Config tweaks

There is onDemandEntries option for next.config.js, can use it to force dev server to store more compiled pages in memory, so you will see fewer compiling /page ... lines.
For example:

const nextConfig = {
  onDemandEntries: {
    // period (in ms) where the server will keep pages in the buffer
    maxInactiveAge: 15 * 60 * 1000, // 15 minutes
    // number of pages that should be kept simultaneously without being disposed
    pagesBufferLength: 4,
  },
Enter fullscreen mode Exit fullscreen mode

Tnx for reading.

Comments 1 total

  • robert webb
    robert webbNov 11, 2024

    **
    Do you need to increase your credit score?
    Do you intend to upgrade your school grade?
    Do you want to hack your cheating spouse's email, WhatsApp, Facebook, Instagram, or any other social network?
    Do you need any information concerning any databases?
    Do you need to retrieve deleted files?
    Do you need to clear your criminal records with the DMV?
    Do you want to remove any site or link from any blog?
    You should contact this hacker; he is reliable and good at hacking.
    Contact: cybergoldenhacker at gmail dot com

    **

Add comment