`npm run build` sometimes times out building static pages in Next 12 for our repository
See original GitHub issueVerify 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:
- Created a year ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
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 uncommentswrlit
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 importswrlit
.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!
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.