Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

npm run dev says next is not found in a fresh Next.js project

Errornext: command not found

Short answer

npm run adds node_modules/.bin to PATH, so next is found only when the packages are installed. After a clone or a download, node_modules is missing, so run npm install, or npm ci when a lock file exists. If install does not help, check that next is listed in package.json and that a dev script runs next dev.

  • Applies to Next.js 15, Next.js 16, npm 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the two things the command depends on: that node_modules exists, and what package.json says about the dev script.

    ls node_modules/.bin/next; grep -n -A6 '"scripts"' package.json
  2. 2Match what you see, then jump to its fix

    1. 1ls says node_modules/.bin/next does not existDependencies were never installedFix
    2. 2node_modules exists but next is absent, or package.json has no dev entry under scriptsnext is not in package.json, or the dev script is missingFix

What does the error look like?

  • next: command not found
  • npm run dev fails right after cloning a Next.js repository

Cause 1 of 2

Dependencies were never installed

1Check

npm run puts node_modules/.bin on PATH for scripts. A repository cloned from GitHub has no node_modules folder, because it is not committed.

ls node_modules | head -3

2Fix

Install the dependencies. With a package-lock.json present, npm ci installs exactly what the lock file says and fails if the lock file and package.json disagree.

npm install
# or, in a clean checkout with a lock file
npm ci

3Verify

The binary exists and the dev server starts.

ls node_modules/.bin/next
npm run dev

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 2

next is not in package.json, or the dev script is missing

1Check

The installation guide expects next, react and react-dom as dependencies and a dev script that runs next dev.

npm ls next; grep -n '"dev"' package.json

2Fix

Install the packages and add the scripts from the installation guide.

npm i next@latest react@latest react-dom@latest

// package.json
"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start"
}

3Verify

Start the dev server and open http://localhost:3000.

npm run dev

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Add node_modules to .gitignore and put an install step in the README.
  • Commit package-lock.json so npm ci gives the same install every time.
  • Use Node.js 20.9 or newer, the minimum the Next.js docs list.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.