vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.73k stars 26.94k forks source link

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

Closed YassinEldeeb closed 10 months ago

YassinEldeeb commented 2 years ago

Verify 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

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.

pulkitvyas08 commented 2 years ago

Facing the same issue

huanlirui commented 2 years ago

i have same issue !!

huanlirui commented 2 years ago

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

node v14.17.0

benzavision commented 2 years ago

same issue

MarcusHSmith commented 2 years ago

Same issue for us

UmerEdava commented 2 years ago

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.

boiboif commented 2 years ago

same issue!

iamharshad commented 2 years ago

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

Dariocoding commented 2 years ago

I have the same issue!!!

zahydo commented 2 years ago

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

zahydo commented 2 years ago

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 ...
alexrintt commented 2 years ago

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

XahidEx commented 2 years ago

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.+

ruvaz commented 2 years ago

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

XahidEx commented 2 years ago

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. 😅

LordOfTheThunder commented 2 years ago

Mine was solved when downgrading from next 13 to next 12.2

ruvaz commented 2 years ago

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

Krungleviciute commented 1 year ago

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 ?

farro97 commented 1 year ago

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.

Krungleviciute commented 1 year ago

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

boliveros18 commented 1 year ago

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

jucian0 commented 1 year ago

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

edgarhsanchez commented 1 year ago

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 commented 1 year ago

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

asimashfaq commented 1 year ago

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

aitdahane commented 1 year ago

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

GautheyValentin commented 1 year ago

For my part, i was stuck cause of the package react-router-dom I need to stuck on react-router-dom@6.4.4

Maybe it's a deps of router or itself directly

(On next@13.0.6 and next@13.1.0 too)

wenerme commented 1 year ago

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 react-router-dom@6.5.0 works

aitdahane commented 1 year ago

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.

dottodot commented 1 year ago

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

jrmyio commented 1 year ago

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 react-router-dom@6.5.0 works

I had the same issue. However, after updating Next.js and react-router-dom to their latest minor versions, the issue went away.

I am on now on: node 18.12.0 Next.js 13.1.4 react-router-dom 6.7.0

and next:build + next:export starts working again.

GautheyValentin commented 1 year ago

I confirm that's working on : Node : v18.13.0 Next.js : 13.1.5 React Router Dom : 6.7.0

majidsadr commented 1 year ago

I had the same issue with this and figured out there's a problem with withPlugins on exporting in next.config.js file. So instead of writing:

module.exports = (phase, { defaultConfig }) =>
  withPlugins([
    [customNextConfig],
    [withVideos],
    [withTM],
  ])(phase, { undefined });

I tried this:

module.exports = () => {
  const plugins = [customNextConfig, withVideos, withTM];
  return plugins.reduce((acc, next) => {
    return next(acc);
  });
};

And the problem fixed. BTW I've updated react-router and react-router-dom to v6.8.0 before this change.

mrLuisFer commented 1 year ago

Same issue using:

Qquanwei commented 1 year ago

upgrade to next@13.1.6 this issue is gone

colbyfayock commented 1 year ago

it's not completely gone. im still hitting it on 13.1.6 and trying to debug what's causing it

johnzenith commented 1 year ago

Mine was solved after closing the dev server.

anonrose commented 1 year ago

I'm utilizing kepler and minifying the build was taking far too long so I changed swcMinify: false in my next.config.js.

omgpointless commented 1 year ago

Same issue happened to me today. And indeed the culprit was dev server running in a vscode terminal that I had forgotten to close.

Which is fine, if you were given some information about this being the case instead of waiting for infinity.

ishigami commented 1 year ago

Another reason for this:

In my case I was running the NextJS 13 project with NodeJS 18.13.0 switched through nvm (my default NodeJS version is v14.13.1), and I've forgot that I've re-opened the terminal.

When I remembered and switched back to 18.13.0, everything back to normal.

🤦

andersekdahl commented 1 year ago

I had this issue when there was code that depended on npm packages that weren't installed. I added this to my next.config.js to see which packages it was:

process.on('unhandledRejection', error => {
  console.log('unhandledRejection', error);
});
RollsChris commented 1 year ago

Hey how do you find out what causing it to hang? there is no verbose flag on the command

mrLuisFer commented 1 year ago

Same issue using:

  • Node: v18.12.0
  • TypeScript: 4.9.5
  • Nextjs: 12.3.2
  • React: 17.0.2 Captura de pantalla 2023-02-03 a la(s) 17 35 31

I solved it by deleting the project and cloning again because in my case there is no possibility to update the nextjs version.

arpadgabor commented 1 year ago

Having the same problem. Not working on 13.1.6, not working on 13.2.4 either, node 16.19 and 18.15 same behaviour. rebooted the pc to kill any possible process, no success. nuked the repository and cloned it, reinstalled everything clean, still not working. and there's no logs either, --debug does nothing.

Edit: Seems like next/font was not able to fetch some fonts and it does not handle the errors... found this by running build inside docker, but in my native shell no errors were reported.

shawnmclean commented 1 year ago

Went up to 3.3.0, got this error, went back to 13.1.6 and it's now working.

ramonfritsch commented 1 year ago

If anyone else is having this issue I'll just put it out there what was happening to me.

Build was stuck on this state but would eventually finish after 10 minutes. This is a long time, specially on a Mac M1. I found out that while refactoring a few things I forgot to update the content on the tailwind config file. It was reading every .js/.ts file inside my huge /node_modules folder, on every single build.

Once I fixed that the build times went back to normal (30 seconds or less).

jelmd commented 1 year ago

FWIW: I got finally a clean build by adjusting the versions in package.json to most recent ones, rm -rf .next node_modules; npm cache clean --force; npm update.

Even so npm cache clean emits bloat about self-healing and bla, --force was required to be able to fetch latest versions/resolve dependencies as needed.

Dependencies used:

    "dependencies": {
        "@next-auth/prisma-adapter": "^1.0.6",
        "@prisma/client": "^4.13.0",
        "next": "13.3.4",
        "nodemailer": "^6.9.1",
        "react": "18.2.0",
        "react-dom": "18.2.0"
    },
    "devDependencies": {
        "@types/node": "18.16.3",
        "@types/nodemailer": "^6.4.7",
        "@styled-icons/material": "^10.47.0",
        "@types/react": "18.2.0",
        "@types/react-dom": "18.2.1",
        "eslint": "8.39.0",
        "eslint-config-next": "13.3.4",
        "prisma": "^4.13.0",
        "typescript": "5.0.4"
    }
ayushsgithub commented 1 year ago

The same problem existed in my code also but it solved when I closed and restarted everything, but got another error Export encountered errors on following paths: / Error: Command "npm run build" exited with 1

Josh-Savvy commented 1 year ago

This is my own issue whenever I try to run a CI build for my nextjs typescript project: Run eslint . --ext .js,.jsx,.ts,.tsx eslint . --ext .js,.jsx,.ts,.tsx shell: /usr/bin/bash -e {0}

[debug]/usr/bin/bash -e /home/runner/work/_temp/d1b0ccf4-4fa4-4121-8209-9a8565b5a79d.sh

/home/runner/work/_temp/d1b0ccf4-4fa4-4121-8209-9a8565b5a79d.sh: line 1: eslint: command not found Error: Process completed with exit code 127.

[debug]Finishing: Run ESLint

joacub commented 1 year ago

Having the same problem. Not working on 13.1.6, not working on 13.2.4 either, node 16.19 and 18.15 same behaviour. rebooted the pc to kill any possible process, no success. nuked the repository and cloned it, reinstalled everything clean, still not working. and there's no logs either, --debug does nothing.

Edit: Seems like next/font was not able to fetch some fonts and it does not handle the errors... found this by running build inside docker, but in my native shell no errors were reported.

same here, never finished, seems the next/font package in a docker env.