
Launch a Next.js app without manual setup delays
How do I fix the npm command not found?
How do I fix npm not found on Mac?
How to install npm in the Mac terminal?
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:
npx create-next-app my-app cd my-app npm install npm run dev
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:
pwd # shows your current directory ls # verifies presence of package.json and node_modules
If you see package.json with Next.js in dependencies or devDependencies, but node_modules/.bin/next is missing, try:
npm install
This reinstalls all dependencies, repopulates .bin, and makes the next development, build, or start available. If still missing, consider deleting node_modules and reinstalling:
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:
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:
You resolve it by installing the missing package:
Then rerun . That often resolves common build errors in a Next.js app.
Once development is working, you run:
which typically maps to the next build. That compiles your project into optimized production files. If you see a error here, it usually means your doesn’t have the right script, or you’re outside the project directory.
After a successful build, you launch with:
Which is the next start? That spins up a production server.
If next start fails, ensure the 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:
which likely maps to next lint. If that fails with a command-not-found error, add a lint script:
In your package.json scripts section, ensure is installed as a .
Sometimes, builds or Failures can occur due to misconfiguration , unexpected exit codes, or plugin issues.
Confirm your scripts include:
Make sure next appears in your dependencies or devDependencies:
If builds fail unpredictably, try deleting the cache:
Then run npm run build again.
If you’re pulling from a repo, run:
Or npm ci for reproducible results.
In case of plugin misbehavior, check 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 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.
Error: Cannot find module 'react-dom'
npm run dev*command not found* package.json.next foldernextdevDependencynpm run devpackage.jsonnext.config.jsnpm installrm -rf node_modules
npm cache clean --force
npm install
npm install -g next
npm install react react-dom
npm run build
npm run start
npm run lint
rm -rf .next
npm install
"lint": "next lint"
{
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
"dependencies": {
"next": "latest"
}