next.js: I ran `next build` but it is saying `next command` not found

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of Next.js: [e.g. 6.0.2]

Additional context

Add any other context about the problem here. I ran next build but it is saying next command not found

next build

Command 'next' not found, but can be installed with:

sudo apt install mailutils-mh
sudo apt install mmh
sudo apt install nmh

I followed above instructions but I am getting same problem.

  • I also used npm install next --save but I am getting same error.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (4 by maintainers)

Most upvoted comments

I fixed this issue by running the below command:

npm i -g next

I fixed the by removing node_modules and added again:

  1. rm -rf node_modules
  2. npm install

ok. I used this command but same problem.

next build

Command 'next' not found, but can be installed with:

sudo apt install mailutils-mh
sudo apt install mmh
sudo apt install nmh

I will throw npx next in.

Have you tried npm run build and npm run start? That worked for me. See the documentation here: https://nextjs.org/learn/basics/deploying-nextjs-app/other-hosting-options.

Add below line in your scripts

"build": "next build && next export",

and then run

`npm run build`

You should install Next.js in your project via:

npm i next

However, we suggest you create an app using Create Next App:

npx create-next-app

I run this command, it worked for me npm install next --save

Why must we prefix with ‘npm’ such as in ‘npm run build’ I know it’s not much extra to type but I am pedantic at getting my setup right. There are some scary approaches to fixing this mentioned here.

You have three options:

  1. Install Next globally with npm i -g next.
  2. Use npx. Install Next with npm i next and when you run any Next command, prefix it with npx, e.g. npx next build or npx next start. It should work.
  3. Create an npm script. In package.json in the scripts section add "build": "next build" and "start": "next start". Then run them with npm run build or npm start, respectively.

I was having the same problem. Running npm i was not adding the Next.js binaries in the node_modules folder for some reason. Tried npm ci and deleting the node_modules folder manually and reinstalling everything with npm i to no avail.

Finally solved the problem by upgrading Next.js to the next minor verison (10.0.8). Now I can see the Next.js binaries in the node_modules folder.