DEV Community

Alex
Alex

Posted on

6 1

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay