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

Solution 1:

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

Solution 2:

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

Solution 3:

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

Solution 4:

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