Next.js Discord

Discord Forum

Long build time on production

Unanswered
Acorn-plum gall posted this in #help-forum
Open in Discord
Acorn-plum gallOP
Hello.
I want to ask if it's ok that when I run a command "npm run build" it takes almost 30 min. to build my app?
And it only if I delete .next folder before running the command.
My production on ec2.
I run "git pull", then "npm run build" and it take forewer and seems like it got stack, so i need to restart bash, reconnect via ssh, delete .next and run "npm run build" one more time and it take 20-30 min to build.
When I run "npm run build" on development mode it works pretty fast even without deletion of .next folder.
I work with App router.
My app is not so big, I think.
Here is the result of my "build" from bash terminal:
 ✓ Creating an optimized production build
 ✓ Compiled successfully
   Skipping linting
 ✓ Checking validity of types
 ✓ Collecting page data
 ✓ Generating static pages (12/12)
 ✓ Collecting build traces
 ✓ Finalizing page optimization
Route (app)                              Size     First Load JS
┌ ○ /                                    1.16 kB         183 kB
├ ○ /_not-found                          0 B                0 B
├ λ /about-us                            859 B           183 kB
├ λ /advertising                         1.1 kB          190 kB
├ λ /privacy-policy                      860 B           183 kB
├ λ /return-and-refund-policy            860 B           183 kB
├ ○ /robots.txt                          0 B                0 B
├ ○ /sitemap.xml                         0 B                0 B
├ λ /terms-of-service                    859 B           183 kB
├ λ /tool/[tool]                         9.73 kB         217 kB
└ λ /tools/[tools]                       19.8 kB         230 kB
+ First Load JS shared by all            112 kB
  ├ chunks/472-01e28145a2616498.js       27.6 kB
  ├ chunks/95-eb1353c72bcfc42a.js        31 kB
  ├ chunks/fd9d1056-476781a83562b96b.js  50.9 kB
  ├ chunks/main-app-798fdb91a49aea3a.js  236 B
  â”” chunks/webpack-30b252052be0d617.js   1.73 kB

17 Replies

@Acorn-plum gall Hello. I want to ask if it's ok that when I run a command "npm run build" it takes almost 30 min. to build my app? And it only if I delete .next folder before running the command. My production on ec2. I run "git pull", then "npm run build" and it take forewer and seems like it got stack, so i need to restart bash, reconnect via ssh, delete .next and run "npm run build" one more time and it take 20-30 min to build. When I run "npm run build" on development mode it works pretty fast even without deletion of .next folder. I work with App router. My app is not so big, I think. Here is the result of my "build" from bash terminal: ✓ Creating an optimized production build ✓ Compiled successfully Skipping linting ✓ Checking validity of types ✓ Collecting page data ✓ Generating static pages (12/12) ✓ Collecting build traces ✓ Finalizing page optimization Route (app) Size First Load JS ┌ ○ / 1.16 kB 183 kB ├ ○ /_not-found 0 B 0 B ├ λ /about-us 859 B 183 kB ├ λ /advertising 1.1 kB 190 kB ├ λ /privacy-policy 860 B 183 kB ├ λ /return-and-refund-policy 860 B 183 kB ├ ○ /robots.txt 0 B 0 B ├ ○ /sitemap.xml 0 B 0 B ├ λ /terms-of-service 859 B 183 kB ├ λ /tool/[tool] 9.73 kB 217 kB └ λ /tools/[tools] 19.8 kB 230 kB + First Load JS shared by all 112 kB ├ chunks/472-01e28145a2616498.js 27.6 kB ├ chunks/95-eb1353c72bcfc42a.js 31 kB ├ chunks/fd9d1056-476781a83562b96b.js 50.9 kB ├ chunks/main-app-798fdb91a49aea3a.js 236 B └ chunks/webpack-30b252052be0d617.js 1.73 kB
Dunker
hello, what is status now
@Dunker hello, what is status now
Acorn-plum gallOP
Hello, it built, website works with all changes that I want. The question is, whether it's ok the BUILD takes so much
are you sure its the build thats taking a long time?
and not the install of packages?
Also to compare, how long does it take to a build locally?
Also what are the specs of the ec2 box?
@linesofcode are you sure its the build thats taking a long time?
Acorn-plum gallOP
"and not the install of packages?" No, I installed all nedded packages before running build command
"Also to compare, how long does it take to a build locally?' Couple minutes
"Also what are the specs of the ec2 box?" t2.micro. Or you meant somthing other?
@Dunker are you seeing any build logs at anywhere
Acorn-plum gallOP
I see logs /var/log/nginx/error.log or /var/log/nginx/access.log, but it seems it doesn't show something that would be related to build process.
If you know any way to see specifically build logs, I will be glad to find out ones
@Dunker where you know your build takes 30 min, i need that place. we need build logs to see everything step by step
Acorn-plum gallOP
I just "npm run build" and wait until my terminal shows me that everything is built (see the image). It takes 30+- minutes.
@Acorn-plum gall I just "npm run build" and wait until my terminal shows me that everything is built (see the image). It takes 30+- minutes.
Dunker
Looks like problem is your ec2, cuz it has 1 vcpu 1gb ram , for example i have 2cpu, 16gb ram and my build takes around minutes
If you can, try to deploy same app via GitHub to vercel, and tell if anything changes
@Dunker Looks like problem is your ec2, cuz it has 1 vcpu 1gb ram , for example i have 2cpu, 16gb ram and my build takes around minutes
Acorn-plum gallOP
Maybe it's because weak server, but the problem began only week ago. Before, it built fast.
It occurred to me , that it may be because MY laptop is not so powerful. It works slowly enough when a lot off apps and windows are opened. And I noticed that, when I restart my laptop, it build fast. If this is the reason, I wonder why it is, because I thought that when I connect via ssh via bash terminal it build command uses only c2 resources, but not ones of my laptop. So, is it possible, that laptop power cause this problem? E.g. now, I deleted zoom from my laptop, restarted it and it built very fast (I deleted zoom, just in case, because I recalled that I installed zoom 1-2 weeks ago , by the way, maybe it's because zoom? :)).
@Dunker but we re talking about ec2, you already said your local builds are fast
Acorn-plum gallOP
Yes, indeed. I'm confused. Thank you for your help. I'm going to test some things to figure out the issue. I'll write if something is interesting.