next.js icon indicating copy to clipboard operation
next.js copied to clipboard

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

Open YassinEldeeb opened this issue 2 years ago • 21 comments

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:

$ yarn next build
yarn run v1.22.17
$ C:\development\activity-builder\node_modules\.bin\next build
info  - Loaded env from C:\development\activity-builder\.env
info  - Checking validity of types  
warn  - The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config

./src/components/Activities/ActivityQuestions/DynamicQuestionTypes/MultipleChoice.tsx  
68:40  Warning: Forbidden non-null assertion.  @typescript-eslint/no-non-null-assertion
69:22  Warning: Forbidden non-null assertion.  @typescript-eslint/no-non-null-assertion

./src/components/Activities/ActivityQuestions/Question.tsx
102:13  Warning: Unexpected console statement.  no-console

info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
info  - Creating an optimized production build  

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 linked above.

YassinEldeeb avatar Jun 19 '22 16:06 YassinEldeeb

Facing the same issue

pulkitvyas08 avatar Jul 02 '22 09:07 pulkitvyas08

i have same issue !!

huanlirui avatar Jul 11 '22 07:07 huanlirui

Execute the steps of “ creating an optimized production build ” on the Linux server

node v14.17.0

huanlirui avatar Jul 13 '22 07:07 huanlirui

same issue

benzavision avatar Jul 15 '22 11:07 benzavision

Same issue for us

MarcusHSmith avatar Jul 15 '22 13:07 MarcusHSmith

The same issue still exists.... any remedies. In my case, it was hours I stuck at this "creating an optimized production build". And also I didn't run the development server in the background.

UmerEdava avatar Jul 26 '22 13:07 UmerEdava

same issue!

boiboif avatar Jul 28 '22 14:07 boiboif

Same issue for React.js project as well even when development server is not running on

iamharshad avatar Jul 29 '22 13:07 iamharshad

I have the same issue!!!

Dariocoding avatar Aug 08 '22 22:08 Dariocoding

Same Issue. In development it worked, but when I try to create the Docker image it stuck

zahydo avatar Sep 01 '22 14:09 zahydo

Same Issue. In development it worked, but when I try to create the Docker image it stuck

I solved with the next steps:

  1. Upgrading Next to v12.2.5.
  2. Removing local folders: .next, node_modules
  3. Installing dependencies again: yarn install
  4. Adding this to next-config.js: output: 'standalone'
  5. Adding the next paths to the .dockerignore: Dockerfile .dockerignore node_modules npm-debug.log README.md .next docker .git
  6. Creating the image again: docker build ...

zahydo avatar Sep 01 '22 15:09 zahydo

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

Same issue but I wasn't aware that this was happening due the open dev webserver.

So the solution for me is on your title: close the development server, then run next build and next export (If you intend to deploy statically).

alexrintt avatar Sep 15 '22 01:09 alexrintt

I am still facing the same issue. Using the latest NextJs 12.3.2-canary.34 facing this issue since I'm trying 12.3.2-carany.+

XahidEx avatar Oct 23 '22 09:10 XahidEx

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

ruvaz avatar Oct 29 '22 03:10 ruvaz

Mine was also solved. I faced this issue because a dependency wasn't comfortable with the latest nextjs. 🙃 Vercel didn't show the error anyway. It was just stuck. 😅

XahidEx avatar Oct 29 '22 04:10 XahidEx

Mine was solved when downgrading from next 13 to next 12.2

LordOfTheThunder avatar Oct 29 '22 14:10 LordOfTheThunder

Try by Tracing warnings with node: npx cross-env NODE_OPTIONS="--trace-warnings" yarn build

ruvaz avatar Oct 31 '22 16:10 ruvaz

I am having the same issue! I tried all the possible solutions, but cannot find the reason why it's stuck on "Creating an optimized production build.." I get

info  - Linting and checking validity of types  
info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
info  - Creating an optimized production build . .

Something is not compiling right maybe ?

Krungleviciute avatar Nov 09 '22 17:11 Krungleviciute

Make sure you don't run development and build the at the same time. I got my build running forever till I closed my dev server and it completes my build process.

farro97 avatar Nov 12 '22 12:11 farro97

Yeah, I tried that, I tried removing package-lock and node modules and reinstall everything.. Nothing helped. And I don't know where to even start debugging. There might be something in the config file that blocking it. I am trying to update to nextjs v12.3.2 and using antd 4.23.6. In the next.config.js file under webpack config I had this block:

    if (isServer) {
      const antStyles = /antd\/.*?\/style.*?/;
      const origExternals = [...config.externals];
      config.externals = [
        (context, request, callback) => {
          if (request.match(antStyles)) return callback();
          if (typeof origExternals[0] === 'function') {
            origExternals[0](context, request, callback);
          } else {
            return callback();
          }
          return null;
        },
        ...(typeof origExternals[0] === 'function' ? [] : origExternals),
      ];

      config.module.rules.unshift({
        test: antStyles,
        use: 'null-loader',
      });
    }

when removed this block it gave me errors in the logs that it failed to compile and that it couldn't import Alert, message and badge components from antd (which I use more than just those). I don't know what is causing everything and where is the issue

Krungleviciute avatar Nov 13 '22 17:11 Krungleviciute

Mine was solved when downgrading from next 13 to next 12.2

To upgrade you can run the following command in the terminal:

npm install next@12 or

yarn add next@12

then, delete .next folder and build next project:

npm run build

boliveros18 avatar Nov 17 '22 15:11 boliveros18

I faced the same error using next v13, updating to 13.0.5 the error is gone.

jucian0 avatar Nov 25 '22 01:11 jucian0

I faced the same error using next v13, updating to 13.0.5 the error is gone.

I'm on 13.0.2 and it hangs. I'm going to try to move to latest.

edgarhsanchez avatar Nov 28 '22 15:11 edgarhsanchez

Moving to 13.0.5 worked. Makes me think there is some kind of bug that keeps creeping up in the builder since I see it's been showing up in different versions going back to 12.x.x

edgarhsanchez avatar Nov 28 '22 15:11 edgarhsanchez

My stuck due to tailwind. I remove those and it work.

asimashfaq avatar Dec 07 '22 17:12 asimashfaq

Any new about it. I am having the same problem when building docker image and upgrading from node 14 to node 16

aitdahane avatar Dec 22 '22 22:12 aitdahane

For my part, i was stuck cause of the package react-router-dom I need to stuck on [email protected]

Maybe it's a deps of router or itself directly

(On [email protected] and [email protected] too)

GautheyValentin avatar Dec 24 '22 05:12 GautheyValentin

next 13 with react-router-dom Build log https://vercel.com/wener/apis/GFynQQEqTYxLxPS2GJf6zt3eQTAM Project code https://github.com/wenerme/wode/tree/develop/apps/apis

Same repo, but another project do not have this problem https://github.com/wenerme/wode/tree/develop/apps/demo Build log https://vercel.com/wener/wode/HvcVKX24v6KoA7T3D6mjs6pRTmrv


downgrade to [email protected] works

wenerme avatar Jan 04 '23 08:01 wenerme

Any new about it. I am having the same problem when building docker image and upgrading from node 14 to node 16

In my case, it was related to some devDependencies that should be moved to dependencies.

aitdahane avatar Jan 05 '23 09:01 aitdahane

I have the same issue using the latest version in my bitbucket pipeline however if I rollback to 13.0.7 it builds ok. The pipeline just gets stuck and doesn't error. I've not tried anything in between as yet to find the exact version where the issue starts. Also not seeing this when building locally

dottodot avatar Jan 16 '23 21:01 dottodot