when I hit yarn run dev . it shows 'next' is not recognized as an internal or external command, operable program or batch file

Viewed 35830

I've installed yarn create next-app my-app. Then when I tried to run this command yarn dev It shows the error next is not recognized as an internal or external command, operable program or batch file.

Please provide the solution. I've already spent the whole day to fix this :(

8 Answers

this is because your system does not have the "next npm"

follow to fix:

  1. visit your project dir
  2. open terminal
  3. hit the command npm install next

Try following steps:

npx create-next-app project-name
cd project-name
npm run dev

# or

yarn create next-app project-name
cd project-name
yarn dev

If you are still facing the same issue then try Manual Setup:

npm install next react react-dom
# or
yarn add next react react-dom

Then, open package.json and add the following scripts:

"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start"
}

For more info or help, please visit: NextJS Getting Started

Do Manually Setup. It will work for you. If you are in Visual Studio Code then follow this step:

  1. Go to Terminal > New Terminal
  2. cd Your file name (for example my-project is my file name than cd my-project)
  3. Next Copy the following command
npm install next react react-dom
OR
yarn add next react react-dom

Follow steps for solution :

this is solution for all OS like windows ,ubuntu

  1. Open Terminal / command prompt

  2. Install next in your system with this command

npm install next -g

Now close terminal and open it again next --help. You can see now your able to use next command in your whole system

same error. I corrected by running npm install next react react-dom than add import React from 'react' in _app.js

i fixed this with adding absolute path to the script with current project's next command file

"devwin": "./node_modules/.bin/next.cmd dev -p 3005"

path for window

I was facing the same issue. Even though my package.json had "next" as below:

"dependencies": {
    "next": "latest", // like this
    "next-auth": "^3.29.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
},

But running yarn run dev or yarn dev gave the same error that next is not recognized...

I fixed it by running yarn add next which made my package.json dependencies as:

"dependencies": {
    "next": "^11.1.2", // this changed
    "next-auth": "^3.29.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },

Then on yarn run dev the error didn't show up.

I'm pretty late for this debate, but it can be solved deleting .next folder from your project and rebuilding it with yarn dev.

Hope it work for you!

Related