15

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Dayvvo
  • 231
  • 1
  • 2
  • 8

8 Answers8

24

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.

EcksDy
  • 1,289
  • 9
  • 25
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

Dayvvo
  • 231
  • 1
  • 2
  • 8
3

I had the same issue too.

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

2

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

2

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 :)

Oded Ben Dov
  • 9,936
  • 6
  • 38
  • 53
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

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

Dayvvo
  • 231
  • 1
  • 2
  • 8
-1

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"