reactjsnode.jsnpmnext.js

Run of a next js app stuck, npm run dev doesn't work


When I created a simple next.js app, and started it with npm run dev, it worked. When I tried it to start a second time, it was stuck: Stuck Next.js app

I tried to create a new project... the same scenario.

Other React apps (without Next.js) are working correctly.

Do you have any ideas on how to fix it, please?

Thanks.

I tried to "kill" Node process. I am using Windows 10.


Solution

  • TLDR

    It sounds like a corruption in Next.js. Try deleting cached files, turning off file syncing, or upgrading your Next.js and Node installation.

    1. Delete the .next folder

    Sometimes the .next folder can become corrupted resulting in errors like this.

    a. On Mac press CTRL + C on windows CTRL + C to kill the terminal

    b. Delete the .next folder

    c. Run the command npm run dev and give it time as the .next folder is rebuilt and runs the app

    2. Reinstall all dependencies

    If the first method doesn't work then you can conclude the .next folder is likely not the problem. The issue could be corrupted dependencies.

    a. Kill the terminal

    b. Delete node_modules

    c. Run the command npm install to reinstall all the dependencies

    3. Clear Node.js cache

    It's possible that Node has cached corrupted files.

    a. Kill the terminal

    b. Run the command npm cache clean --force

    4. Disable file syncing for cached files

    Ensure that your computers cloud syncing does not sync cached files such as those in .next. I recommend ignoring all files in your .gitignore. Or at a minimum: .next, node_modules, dist.

    5. Repair the Node.js installation

    If the above is working or the command cannot run do to NPM being frozen you can try repairing the Node.js installation.

    On windows

    a. Open file explorer

    b. Navigate to downloads

    c. Open Node.js installer

    d. In the popup that will appear select "repair"

    On mac

    a. Kill the terminal

    b. Follow this guide to uninstall and reinstall Node.js

    6. Update Node.js

    I would recommend this before trying next@canary

    If you have already tried step 4. Skip this step. You are already on the latest version.

    a. Kill the terminal

    b. Go to where ever your Node installation is and uninstall it

    c. Go to nodejs.org to install the latest version of Node. Check out this article for how to choose between LTS and current

    d. After installing, re-run npm run dev

    7. Install Next.js canary

    If none of this works install the canary version of Next.js. This is a version of Next.js released daily with bug fixes not yet in the stable version of Next.js.

    a. Kill the terminal

    b. Run the command npm install next@canary

    8. Try a different package manager

    There is a problem you likely can't fix on your own. Try a different package manager to see if the problem only affects npm.

    a. Kill the terminal

    b. Follow pnpm's guide for installation on your OS

    If all else fails it's likely a bug in Next.js. I would recommend opening a Github issue that way the problem gets fixed ASAP.