FG
๐ŸŒ Web & Full-StackVercel

Stuck on `Creating an optimized production build` forever when development server is running

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score85%
85%

Problem

Verify canary release - [x] I verified that the issue exists in Next.js canary release Provide environment information Operating System: Platform: win32 Arch: x64 Version: Windows 10 Pro Binaries: Node: 16.13.0 npm: N/A Yarn: N/A pnpm: 6.24.0-1 Relevant packages: next: 12.1.4 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 I had my development server running in the background without me remembering and I wanted to build my app using `next build`, that's what I've got: [code block] And I was stuck for 30 minutes on `info - Creating an optimized production build` without any indication of anything being wrong, I noticed that the development server was running, after I've shut it down and ran `next build` again It compiled successfully. Expected Behavior - Run `next build` to compile the app for production even when I'm running the development server. OR - Notify me that the development server is running and needs to be shut down before running `next build`, that's in case running `next build` when `next` is running isn't possible. Link to reproduction https://github.com/YassinEldeeb/Next.js-starter To Reproduce 1. Run `next` for the development server. 2. Then run `next build` while the development server is running. Note: It's not specific to the repository lin

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Prevent Build Process When Development Server is Running

Medium Risk

The Next.js build process (`next build`) cannot run concurrently with the development server (`next`). When both processes are active, the build process hangs indefinitely because it cannot access the necessary resources or ports. This is a known limitation in Next.js where the build command expects a clean environment without other Next.js processes running.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Check for Running Development Server

    Before executing the `next build` command, check if the development server is currently running. This can be done by looking for any active processes related to Next.js or checking the terminal for running instances.

    bash
    tasklist | findstr node
  2. 2

    Terminate Development Server if Running

    If the development server is found to be running, terminate it to free up resources. This can be done using the command line or task manager. Use the following command to kill the process if it's identified in the previous step.

    bash
    taskkill /F /IM node.exe
  3. 3

    Run Next Build Command

    After ensuring that the development server is no longer running, proceed to run the `next build` command to compile the application for production.

    bash
    next build
  4. 4

    Implement Pre-Build Check Script

    To automate the process, create a script that checks for the running development server before executing the build command. This script can be added to your package.json as a pre-build step.

    json
    "prebuild": "tasklist | findstr node || exit 1"

Validation

Confirm that the build process completes successfully without hanging. Additionally, ensure that the pre-build check script correctly identifies when the development server is running and prevents the build from starting.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

nextjsreactssrbug