DEV Community

Alex
Alex

Posted on

Solving slow compilation in dev mode for Next.js

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.

Top comments (0)