question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`npm run build` sometimes times out building static pages in Next 12 for our repository

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
Binaries:
  Node: 16.13.1
  npm: 8.1.2
  Yarn: 1.22.4
  pnpm: N/A
Relevant packages:
  next: 12.1.1-canary.18
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Various pages in our app often time out during static page generation when using Next 12. We first noticed this in our Vercel builds, where they time out occasionally, but have recently been able to reproduce this fairly reliably on the command line.

Using node 17 seems to make this worse, but it does happen fairly reliably on 16 as well. Different pages time out in different builds, ie build 1:

info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
warn  - Restarted static page generation for /u/[handle] because it took more than 60 seconds
warn  - See more info here https://nextjs.org/docs/messages/static-page-generation-timeout
info  - Generating static pages (14/14)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ /                                      2.29 kB         754 kB
β”œ   /_app                                  0 B             615 kB
β”œ β—‹ /404                                   197 B           615 kB
β”œ Ξ» /api/fetch-og-tags/[encodedUrl]        0 B             615 kB
β”œ Ξ» /api/setup-gnome                       0 B             615 kB
β”œ β—‹ /login                                 1.45 kB         649 kB
β”œ β—‹ /login/[handle]                        485 B           615 kB
β”œ β—‹ /logout                                740 B           622 kB
β”œ β—‹ /privacy                               750 B           677 kB
β”œ β—‹ /register                              3.92 kB         652 kB
β”œ β—‹ /settings                              4.94 kB         709 kB
β”œ β—‹ /tags/[workspace]/[tag]                2.38 kB         679 kB
β”œ β—‹ /tos                                   13.4 kB         689 kB
β”œ β—‹ /u/[handle] (1585 ms)                  1.74 kB         748 kB
β”œ β—‹ /u/[handle]/[workspace]/[name]         6.71 kB         701 kB
β”” β—‹ /u/[handle]/message                    1.16 kB         616 kB
+ First Load JS shared by all              615 kB
  β”œ chunks/framework-7f78491ac389bdeb.js   46.5 kB
  β”œ chunks/main-1b52e6399fb0a6ee.js        27.8 kB
  β”œ chunks/pages/_app-490938265dfdfcce.js  540 kB
  β”œ chunks/webpack-42cdea76c8170223.js     1.07 kB
  β”” css/6f3198be8e019a09.css               9.86 kB

build 2:

info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
warn  - Restarted static page generation for / because it took more than 60 seconds
warn  - See more info here https://nextjs.org/docs/messages/static-page-generation-timeout
warn  - Restarted static page generation for / because it took more than 60 seconds
info  - Generating static pages (14/14)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ / (851 ms)                             2.29 kB         754 kB
β”œ   /_app                                  0 B             615 kB
β”œ β—‹ /404                                   197 B           615 kB
β”œ Ξ» /api/fetch-og-tags/[encodedUrl]        0 B             615 kB
β”œ Ξ» /api/setup-gnome                       0 B             615 kB
β”œ β—‹ /login                                 1.45 kB         649 kB
β”œ β—‹ /login/[handle]                        485 B           615 kB
β”œ β—‹ /logout                                740 B           622 kB
β”œ β—‹ /privacy                               750 B           677 kB
β”œ β—‹ /register                              3.92 kB         652 kB
β”œ β—‹ /settings                              4.94 kB         709 kB
β”œ β—‹ /tags/[workspace]/[tag]                2.38 kB         679 kB
β”œ β—‹ /tos                                   13.4 kB         689 kB
β”œ β—‹ /u/[handle]                            1.74 kB         748 kB
β”œ β—‹ /u/[handle]/[workspace]/[name]         6.71 kB         701 kB
β”” β—‹ /u/[handle]/message                    1.16 kB         616 kB
+ First Load JS shared by all              615 kB
  β”œ chunks/framework-7f78491ac389bdeb.js   46.5 kB
  β”œ chunks/main-1b52e6399fb0a6ee.js        27.8 kB
  β”œ chunks/pages/_app-490938265dfdfcce.js  540 kB
  β”œ chunks/webpack-42cdea76c8170223.js     1.07 kB
  β”” css/6f3198be8e019a09.css               9.86 kB

and sometimes they don’t time out at all:

info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
info  - Generating static pages (14/14)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ /                                      2.29 kB         754 kB
β”œ   /_app                                  0 B             615 kB
β”œ β—‹ /404                                   197 B           615 kB
β”œ Ξ» /api/fetch-og-tags/[encodedUrl]        0 B             615 kB
β”œ Ξ» /api/setup-gnome                       0 B             615 kB
β”œ β—‹ /login                                 1.45 kB         649 kB
β”œ β—‹ /login/[handle]                        485 B           615 kB
β”œ β—‹ /logout                                740 B           622 kB
β”œ β—‹ /privacy                               750 B           677 kB
β”œ β—‹ /register                              3.92 kB         652 kB
β”œ β—‹ /settings                              4.94 kB         709 kB
β”œ β—‹ /tags/[workspace]/[tag]                2.38 kB         679 kB
β”œ β—‹ /tos                                   13.4 kB         689 kB
β”œ β—‹ /u/[handle]                            1.74 kB         748 kB
β”œ β—‹ /u/[handle]/[workspace]/[name]         6.71 kB         701 kB
β”” β—‹ /u/[handle]/message                    1.16 kB         616 kB
+ First Load JS shared by all              615 kB
  β”œ chunks/framework-7f78491ac389bdeb.js   46.5 kB
  β”œ chunks/main-1b52e6399fb0a6ee.js        27.8 kB
  β”œ chunks/pages/_app-490938265dfdfcce.js  540 kB
  β”œ chunks/webpack-42cdea76c8170223.js     1.07 kB
  β”” css/6f3198be8e019a09.css               9.86 kB

Ξ»  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
β—‹  (Static)  automatically rendered as static HTML (uses no initial props)

We’ve tried to verify that there aren’t network requests happening, and indeed this seems to happen even if we strip the _app_ and _document files out.

As far as we can tell this starts happening when we include some of our dependencies in a file, and is not dependent on any particular component/application structure.

Expected Behavior

We expect pages to take roughly the same amount of time to build across different runs as they did in Next 11.

Downgrading to Next 11.1 does seem to fix this, but strangely enough adding a .babelrc to disable SWC builds does not seem to.

To Reproduce

git clone https://github.com/mysilio-co/garden.git
cd garden
git checkout nextjs-bugreport
npm install
npm run build

You may need to run npm run build more than once because unfortunately the results seem to be somewhat nondeterministic - the first time I ran this it completed with:

info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
info  - Generating static pages (14/14)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ /                                      2.28 kB         753 kB
β”œ   /_app                                  0 B             615 kB
β”œ β—‹ /404                                   196 B           615 kB
β”œ Ξ» /api/fetch-og-tags/[encodedUrl]        0 B             615 kB
β”œ Ξ» /api/setup-gnome                       0 B             615 kB
β”œ β—‹ /login                                 1.44 kB         649 kB
β”œ β—‹ /login/[handle]                        483 B           615 kB
β”œ β—‹ /logout                                737 B           622 kB
β”œ β—‹ /privacy                               749 B           676 kB
β”œ β—‹ /register                              3.92 kB         652 kB
β”œ β—‹ /settings                              4.94 kB         708 kB
β”œ β—‹ /tags/[workspace]/[tag]                2.37 kB         678 kB
β”œ β—‹ /tos                                   13.4 kB         689 kB
β”œ β—‹ /u/[handle]                            1.73 kB         747 kB
β”œ β—‹ /u/[handle]/[workspace]/[name]         6.71 kB         701 kB
β”” β—‹ /u/[handle]/message                    1.16 kB         616 kB
+ First Load JS shared by all              615 kB
  β”œ chunks/framework-7f78491ac389bdeb.js   46.5 kB
  β”œ chunks/main-914fbfab4f90b52f.js        27.7 kB
  β”œ chunks/pages/_app-33bda76b787f2992.js  540 kB
  β”œ chunks/webpack-42cdea76c8170223.js     1.07 kB
  β”” css/bc22ef3cff942bbd.css               9.83 kB

but the second time it did this:

info  - Creating an optimized production build
info  - Compiled successfully
warn  - Restarted collecting page data for / because it took more than 60 seconds
warn  - See more info here https://nextjs.org/docs/messages/static-page-generation-timeout
warn  - Restarted collecting page data for /settings because it took more than 60 seconds
warn  - Restarted collecting page data for /u/[handle] because it took more than 60 seconds
info  - Collecting page data
info  - Generating static pages (14/14)
info  - Finalizing page optimization

Page                                       Size     First Load JS
β”Œ β—‹ /                                      2.28 kB         753 kB
β”œ   /_app                                  0 B             615 kB
β”œ β—‹ /404                                   196 B           615 kB
β”œ Ξ» /api/fetch-og-tags/[encodedUrl]        0 B             615 kB
β”œ Ξ» /api/setup-gnome                       0 B             615 kB
β”œ β—‹ /login (1042 ms)                       1.44 kB         649 kB
β”œ β—‹ /login/[handle] (967 ms)               483 B           615 kB
β”œ β—‹ /logout (935 ms)                       737 B           622 kB
β”œ β—‹ /privacy                               749 B           676 kB
β”œ β—‹ /register                              3.92 kB         652 kB
β”œ β—‹ /settings                              4.94 kB         708 kB
β”œ β—‹ /tags/[workspace]/[tag]                2.37 kB         678 kB
β”œ β—‹ /tos                                   13.4 kB         689 kB
β”œ β—‹ /u/[handle]                            1.73 kB         747 kB
β”œ β—‹ /u/[handle]/[workspace]/[name]         6.71 kB         701 kB
β”” β—‹ /u/[handle]/message (989 ms)           1.16 kB         616 kB
+ First Load JS shared by all              615 kB
  β”œ chunks/framework-7f78491ac389bdeb.js   46.5 kB
  β”œ chunks/main-914fbfab4f90b52f.js        27.7 kB
  β”œ chunks/pages/_app-33bda76b787f2992.js  540 kB
  β”œ chunks/webpack-42cdea76c8170223.js     1.07 kB
  β”” css/bc22ef3cff942bbd.css               9.83 kB

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
traviscommented, Mar 31, 2022

Ok @balazsorban44 I’ve managed to narrow down the issue - not terribly surprisingly the problem appears to be our custom swrlit dependency, but since that isn’t a very big repo I suspect the issue might be in one of its dependencies.

I’ve published a minimum-viable reproduction here:

https://github.com/mysilio-co/garden/tree/minimum-reproducible-nextjs-bug

It builds pretty cleanly by default, but if you head into _app.jsx and uncomment swrlit the build may time out (it does very reliably for me locally). If you re-comment that and then uncomment the @inrupt/solid-client-authn-browser dependency you’ll see every page jump by 100KB, but builds don’t appear to fully time out the way they do when we import swrlit.

I’m going to keep debugging this as I have time, but if you have any ideas or suggestions on what might be wrong with these packages please let me know!

1reaction
balazsorban44commented, Mar 29, 2022

There should be a .next/trace file after the build. Could you provide it for the different runs (when there is and there is no issue)?

This should help us investigate what’s taking up the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NextJS cannot find a valid build in the '.next' directory
First, remove package-lock.json or yarn.lock files and node_modules folder and make sure you install all the packages again with the yarnΒ ...
Read more >
Build configuration for Azure Static Web Apps - Microsoft Learn
Learn how to control the build process for Azure Static Web Apps.
Read more >
From Command Line | Docs - IONOS Deploy Now
Start from a sample or deploy an existing repository. Static Websites. A static website is delivered to the user's web browser exactly as...
Read more >
[Support Guide] Frequently encountered problems during builds
1. First steps - ruling out the obvious Β· 1.5 Build logs Β· 2. Command not found - we need to know what...
Read more >
Using Npm Scripts as a Build Tool in 2022 - Delicious Brains
Learn to use project specific npm scripts as both a task runner and a build tool, and unlock their advantages over other task...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found