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:
- Go to ‘…’
- Click on ‘…’
- Scroll down to ‘…’
- 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 --savebut I am getting same error.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (4 by maintainers)
I fixed this issue by running the below command:
npm i -g nextI fixed the by removing node_modules and added again:
ok. I used this command but same problem.
I will throw
npx nextin.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 iYou should install Next.js in your project via:
However, we suggest you create an app using Create Next App:
I run this command, it worked for me
npm install next --saveWhy 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:
npm i -g next.npm i nextand when you run any Next command, prefix it withnpx, e.g.npx next buildornpx next start. It should work.package.jsonin thescriptssection add"build": "next build"and"start": "next start". Then run them withnpm run buildornpm start, respectively.I was having the same problem. Running
npm iwas not adding the Next.js binaries in thenode_modulesfolder for some reason. Triednpm ciand deleting thenode_modulesfolder manually and reinstalling everything withnpm ito 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 thenode_modulesfolder.