Sign in
Launch a Next.js app without manual setup delays
Get step-by-step fixes for the zsh: command not found: next error in your terminal. Learn why it happens, how to repair your Next.js setup, and the right commands to keep your development workflow running without interruptions.
You open your terminal, type npm run dev, and instead of your app starting, you see zsh: command not found: next. It’s a common frustration, but the fix is simpler than it looks. This guide explains why it happens, how it relates to commands like next dev and next build, and the steps to get your project running again—fast.
When you type the next command in your terminal and see the error “zsh: command not found: next,” it means zsh cannot locate the binary for next in your system path. You may be trying to run next dev, next build, next lint, or next start, but the shell doesn’t recognize any of those commands because the Next.js CLI isn’t installed globally or you’re in the wrong directory.
You may also encounter this error when running npm run dev or npm run build if your script calls next dev or next build without the necessary dependencies installed or if the project structure is incorrect.
Have you ever wondered why can't we directly execute the adjacent value command like "next dev". Well you can try doing that but you'll come across an error something like "zsh: command not found: next" because there is no such instruction in the operating system. — LinkedIn Post
At its core, this is a command not found error. The terminal looks through your $PATH and local node_modules/.bin for the next command. If it doesn’t find it, you’ll get the “command not found” message. That could be due to a missing installation, wrong package.json scripts, corrupted cache, or being outside the correct project directory.
Often, when creating a next app, you start by running:
1npx create-next-app my-app 2cd my-app 3npm install 4npm run dev 5
But if you run npm run dev in the wrong current directory, or before installing dependencies, you’ll face the dreaded *command not found*
error or an exit code failure.
Check that you are in the right directory:
1pwd # shows your current directory 2ls # verifies presence of package.json and node_modules 3
If you see package.json
with Next.js in dependencies or devDependencies
, but node_modules/.bin/next
is missing, try:
1npm install 2
This reinstalls all dependencies, repopulates .bin
, and makes the next development, build, or start available. If still missing, consider deleting node_modules
and reinstalling:
1rm -rf node_modules 2npm cache clean --force 3npm install 4
That often resolves a found error due to cache corruption or incomplete installs.
If you want to use the next command across other projects without npm run … scripts, you may install it globally:
1npm install -g next 2
Then, the next development, build, or start may work from any terminal within any directory. Be cautious—global installs can lead to version mismatches between projects.
Speed up your Next.js setup with Rocket.new – instantly scaffold, configure, and run projects without repetitive manual steps. Perfect for avoiding setup errors like “command not found” and focusing on coding faster.
Once dependencies and scripts are properly configured in your project’s package.json, npm run dev invokes the next dev command. That starts the development server, which should remain active, watching for changes, logging build output, and providing hot-reload feedback.
If it terminates with a non-zero exit code, check the terminal log. Look out for missing modules (e.g., missing React DOM), wrong imports, or misconfigured plugins.
If the log shows something like:
Error: Cannot find module 'react-dom'
You resolve it by installing the missing package:
1npm install react react-dom 2
Then rerun npm run dev
. That often resolves common build errors in a Next.js app.
Once development is working, you run:
1npm run build 2
which typically maps to the next build. That compiles your project into optimized production files. If you see a *command not found*
error here, it usually means your package.json
doesn’t have the right script, or you’re outside the project directory.
After a successful build, you launch with:
1npm run start 2
Which is the next start? That spins up a production server.
If next start fails, ensure the .next folder
Ensure it exists (created by the next build) and check the terminal for missing files or config issues.
To keep your code clean, you run:
1npm run lint 2
which likely maps to next lint. If that fails with a command-not-found error, add a lint script:
1"lint": "next lint" 2
In your package.json scripts section, ensure next
is installed as a devDependency
.
Sometimes, builds or npm run dev
Failures can occur due to misconfiguration package.json
, unexpected exit codes, or plugin issues.
Confirm your scripts include:
1{ 2 "dev": "next dev", 3 "build": "next build", 4 "start": "next start", 5 "lint": "next lint" 6} 7
Make sure next appears in your dependencies or devDependencies:
1"dependencies": { 2 "next": "latest" 3} 4
If builds fail unpredictably, try deleting the cache:
1rm -rf .next 2
Then run npm run build again.
If you’re pulling from a repo, run:
1npm install 2
Or npm ci for reproducible results.
In case of plugin misbehavior, check next.config.js
and versions of plugins—they may need updates or reconfiguration.
Through writing this, I understood how common the "zsh: command not found: next" error is when the next command isn’t properly installed or invoked. Ensuring that npm install
is run in the correct directory, that scripts point to valid commands, and that dependencies like next, react, and react-dom are present prevents many errors.
As a next step, consider setting up real-time monitoring of your dev server logs and using continuous integration to catch missing dependencies or script failures early. Adding terse lint checks before production builds helps ensure smoother deployments.