npm run dev says next is not found in a fresh Next.js project
next: command not foundShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
What does the error look like?
next: command not foundnpm 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 -32Fix
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 ci3Verify
The binary exists and the dev server starts.
ls node_modules/.bin/next
npm run devConfirmed by docs.npmjs.com
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.json2Fix
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 devConfirmed by nextjs.org
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
Web apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fixWeb apps
Jest fails with SyntaxError: Unexpected token when testing a Next.js component
Jest failed to parse a file.
Jest only understands plain JavaScript until a transform and a few file mappings tell it more.
3 causes, each with a fix