1

So I've just created a NextJS project using create-next-app which went smoothly as expected. Then ran npm i just to be sure and saw all modules installed into node_modules

When I try to run npm run dev to start my nextjs app. it just says

sh: next: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] dev: `next dev`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/john.v.n.pakson/.npm/_logs/2022-10-06T08_01_29_725Z-debug.log

It seems like npm is not detecting the node_modules i have installed.

Not sure if this is a mac or a zsh issue.

I'm using node version 12.22.12

Upgraded to 16.17.1 and still see the same error

> [email protected] dev
> next dev

/var/folders/6y/xtlzp4z16dj0stxnqx8znj8w0000gn/T/dev-01c08137.sh: line 1: next: command not found
4
  • Did you install your "global" next? npm install -g global or Yarn equivalent if using that. Commented Oct 6, 2022 at 8:15
  • Is it required to install next globally? Commented Oct 6, 2022 at 8:21
  • no, it is not required globally, try removing node_modules and doing a npm install to see if that fixes it Commented Oct 6, 2022 at 8:24
  • hmmm reason actually is my file path. my project was in a folder with Project/Test as a name. I assume npm or zsh got confused cause once I moved it to another folder I could run npm run dev already Commented Oct 6, 2022 at 8:27

1 Answer 1

2

Okay I figured it out. It was caused by my file path on macos. My project was on a folder called Project/Test which might have confused zsh or mac. This in turn caused npm to not be able to find the correct scripts on my node_modules

When I moved my project to another folder I was already able to run npm run dev properly.

Cheers!

Sign up to request clarification or add additional context in comments.

1 Comment

Putting a / in a directory name is one way to really confuse things. Good catch!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.