Next Build hangs forever
Asked Answered
B

12

19

I'm building an app with NextJs and Typescript. I'm trying to run next build (yarn build) on my local machine to check for typescript warnings and build errors before deploying.

Next build hangs at 'Creating an optimized production build' and hangs forever. Don't even know where to start to address this issue. Can anyone help with this?

Bebel answered 13/6, 2021 at 8:35 Comment(0)
P
30

Could be a cache issue.

I'd start by removing /.next folder, if it didn't work then both /.next and /node_modules. Whenever you have issues with Next you don't know how to approach or it's just acting weird - removing /.next will solve most of the problems.

Paraprofessional answered 13/6, 2021 at 13:5 Comment(3)
Also, make sure that your server isn't running in the background. Happened to me.Dyan
That's work after finding a solution for 5 days. Thaks a lot brother.Schooner
My ubuntu server continued to freeze while trying to npm run build. It freezes at Creating an optimized production build ... -- deleteing /next solved the problem. ThanksCrinoid
B
4

Have found the solution to the issue. Apparently the build freeze was caused by empty files located all over my project directory. Removed all of them and next build runs

Bebel answered 18/6, 2021 at 6:51 Comment(0)
A
4

I had the same issue too.

I solved it by upgrading node version from v16.13.0 to v16.14.0.

Agretha answered 11/3, 2022 at 22:39 Comment(0)
I
3

Tried all the excellent suggestions here, but for me the problem was with optimizing one of the external packages. Since performance wasn't a big issue for me, skipping minifying solved it.

You need this in your next.config.js:

const nextConfig = {
  swcMinify: false, // 'minify' in Next versions < 12.0
}

And to make sure this works, I reiterated all the above comments to make sure I wasn't hanging on one of the billion previous attempts :)

Ingratiate answered 19/12, 2022 at 18:37 Comment(1)
this one did the trick for me :)Mako
S
2

Make sure you stoped all servers that running in the background Use npx kill-port 3000

Stob answered 28/6, 2022 at 3:30 Comment(0)
P
1

You can't have both dev and build at the same time.

I solved it very quickly when I realized that there were several nodejs processes open when there should only be 1, and killing all the nodejs processes that were running in the background solved it for me.

It can also happen that a build started to fail and got stuck in the background so you should kill all the nodejs you see running in the task manager. I am using Nextjs 13

Percept answered 29/10, 2022 at 3:52 Comment(1)
this worked for me. I tried building 3 times and I get confused why its taking so much time. lolParthenope
M
1

check the development server (npm run dev). If it's running stop it. delete this folders & file : next, node_modules, package-lock.json

rm -rf .next/ node_modules/ package-lock.json

I fixed the problem with these

Mcclenaghan answered 2/11, 2023 at 10:41 Comment(0)
M
1

Make sure to kill the dev server before running the build

Maice answered 29/5, 2024 at 14:19 Comment(0)
B
0

So the issue with it was that I had an empty file somewhere in the app. Apparently the empty file was what was hanging the build

Bebel answered 27/6, 2022 at 16:32 Comment(0)
P
0

I was using Antd library and because of the below line the build was getting stuck.

import { List, Table, Typography } from "antd";

const { Text } = Typography;

As per Antd docs we are not supposed to use sub-components: https://ant.design/docs/react/use-with-next enter image description here

After removing this line it started working.

Had to manually comment code every file and uncomment one by one and build to find this issue. Really sad that the next build process does not give any info or error when this happens.

Anyways if you are using Antd maybe this will save you few hours.

Pigweed answered 5/5, 2024 at 5:10 Comment(0)
T
0

After trying all recommendation here and all are not working, I just found out the reason after 24 hours of debugging is @next/font package, removing it completely fixes my issue. The main reason is that most of the time it fail to download fonts without showing any signs of error.

I commented this line from layout.tsx:

import { Inter } from 'next/font/google';

Hope this helps you guys, cheers!

Thymic answered 29/5, 2024 at 14:2 Comment(0)
R
-2

I solved it downgrading npm version to v8.5.5. I was testing using v8.12.2 and it always keep in "Checking validity of types"

Reconciliatory answered 22/6, 2022 at 8:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.