What to do when "npm run dev" is not working? (React)

Hi there!

I tried to start my application with “npm run dev” as it is a react / next.js app. The console gave me an error sh: next: command not found. I deleted the node_modues folder and installed it again, even then I still get this error sh: next: command not found.

I can not remeber that I changed something, so I am curious why this error appears. Can someone can help me here?

What I need to do to run my application with npm run dev?

Thanks for help!!

This is the error message I get when I try to start the server from npm scripts:

> Executing task: npm run dev <


> dev
> next dev

sh: next: command not found
The terminal process "/bin/zsh '-c', 'npm run dev'" terminated with exit code: 127.

Terminal will be reused by tasks, press any key to close it.

Is the console/terminal opened in the root folder with the package.json file? What does the scripts part of the package.json file look like (post it).

Is the console/terminal opened in the root folder with the package.json file?

What do you mean by that? I opened the terminal inside VS Code.

What does the scripts part of the package.json file look like (post it).

This is the package.json file:

{
  "name": "nextjs-boilerplate",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "12.0.7",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "eslint": "8.5.0",
    "eslint-config-next": "12.0.7",
    "sass": "^1.45.1"
  }
}

This is a Next JS boilerplate I made a few weeks before, now it is not running the command npm run dev anymore. I also habe some issues with webpack, is it possible that it has something to do with that?

Thanks for help!!

So if you do a ls does it list the package.json file?

It seems to me you might not have the terminal open inside the root folder of the project.

1 Like

It shows the package.json when I do a ls command, here is a screenshot from the terminal:

It seems that it failed to load webpack?

Seem like a missing webpack dependency, not sure what would cause it.

How did you create/set up the Next project?

Try using create-next-app instead, if you didn’t (don’t think you did).

npx create-next-app nextjs-app


Edit: Actually your package.json does look like what you would get with create-next-app

Where is the bundler folder coming from? I wouldn’t expect to see that in a create-next-app (not that I’m much of a Next.js user).

Yes I did created the Next Project with npx create-next-app and I tested the boilerplate, before everything worked fine.

The wired thing is that in another app the npm run dev command is working.

I dont know where the bundler folder is coming from. I thought this is a normal proccess within Webpack to bunde everything for deployment?

I stuck hard and dont know where to start fixing this issue…

That folder doesn’t show up in my Next apps, and it should build to a .next folder.

Try deleting the bundler folder (or just move it out so you still have a copy)

Ok I deleted the bundler folder, but nothing changed. It is a folder which will be created when webpack is used.

I also tried it with another project where the bundler folder was never included and there I got this simple error message:

I wonder why there is sh: and next: this is not common i guess…

Maybe it has something to do with the terminal? I am not sure what exactly a shell is, but I think it could be possible that something with the terminal command is not working, because I did not change anything within the project and before it was working.

I’m pretty sure the bundle folder doesn’t belong in a create-next-app. If you create a new project using create-next-app and just run npm run dev what happens?

I haven’t really used Zsh much. Do you have another terminal you can try instead?

If you click the down-arrow next to the plus sign you should (maybe) have other terminal options (just to test it).

terminal-select

Thank you a lot for helping me!

I tried it with bash (another terminal), but it was not working eather. I am running out of energy now and need to make a break. I try to create a new project tomorrow and if ir is not working I can also create a repo because I dont have any idea whats the issue here right now…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.