Node Nodemon Error: Cannot find module 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'
Asked Answered
E

10

8
  • I am a beginner at NodeJS stuff.
  • Environment is Windows 7 64 Bit.
  • Node is installed and working.
  • NPM is also working fine.
  • Nodemon is installed. (In App and also Globally)

Now when I run the command:

"nodemon server.js" or just "nodemon"

it gives the following error:

module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
  • I don't understand what this means? And why is it looking inside the Git folder?
  • Does it have to do anything with Environment Variable? But Node and NPM are both working fine.
  • Any ideas/suggestion/solution?

Below is my "server.js" file in case you need for reference.

var express = require("express");
var bodyParser = require("body-parser");
var morgan = require("morgan");
var path = require("path");

var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

app.use(function (req, es, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Methods", "GET, POST");
    res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
    next();
});

app.use(morgan("dev"));
app.use(express.static(__dirname + "/app"));
app.get("*", function (req, res) {
    res.sendFile(path.join(__dirname + "/index.html"));
});

app.listen(8080);
console.log(">>>>> App is Running <<<<<");
Eurystheus answered 29/3, 2018 at 14:42 Comment(8)
have you installed nodemon? I recommend you not install it globally. Use command npm install --save nodemon. Then go to your package.json, put this line in your scripts "server": "nodemon server.js". Finally, npm run server to run your appLorca
Write a Nodejs Script that just console.log("hello") and run that with nodemon (no other includes, no logic) and see what happensVulture
please try to do this " npm install --save -g nodemon " -g flag will install it globallyTwibill
Hey Guys. I tried everything. Installing Locally, installing globally, running App with just "console.log()". Even altering "package.json" file. But no matter what, it's giving the same error when I run any command with nodemon.Eurystheus
I inserted the line "start": "nodemon server.js" in the scripts section of package.json. Now, when I run the command "npm start", it is Working. This is similar to what is suggested by @dnp1204. I don't know what was the issue with the current configuration, but this worked. Thanks to all of you for trying to help me out. Appreciated.Eurystheus
The issue is you had install the nodemon but not on the correct path.Shiver
How to check the path and what should be the default path? Because now when I am trying to run "karma init", I am getting the same error. I have installed karma and all the dependencies along with karma cli.Eurystheus
It seems that, this is an issue with MINGW64. If I utilize Windows CMD to run the commands, everything is working fine. Hope this might helps somebody.Eurystheus
A
2

remove node_modules in your project and than install reagain nodemon module, run below commands;

rm -rf node_modules
npm install -g npm@latest
npm i nodemon 
Alviani answered 24/8, 2019 at 9:19 Comment(1)
you are suggesting removing the entire node_modules dir. Thats a bad practice! node_modules might have hundreds of gigabytes of dependencies that have nothing to see with the problematic dependency and you end up creating more problems by reinstalling those.Inexpert
A
1

In my case it was same issue I solved it by mentioned method hope it will help you so in package.json in script tag

  "start":"nodemon index.js"

   

and in terminal with this command run

  nodemon start
Anson answered 25/9, 2021 at 17:8 Comment(0)
S
0

you must validate that the server name (servers.js) is called the same inside the folder, ( package.json ) validate main and start you should not create folders for nodemon.

Shanan answered 12/6, 2020 at 0:33 Comment(0)
V
0

make sure you are running the server.js is in the root directory and run this command in root directory of your project

nodemon ./server.js

Also you can rename server.js to index.js and just run

nodemon

More on nodemon: https://www.npmjs.com/package/nodemon

Vacua answered 10/1, 2021 at 19:15 Comment(1)
You can also set your current working directory inside the script with process.chdir(__dirname);, make sure to put it at the very top.Caucasia
B
0

Use command: npm run server and not nodemon server.js you will get exact error that which module is missing.

Bolster answered 23/7, 2021 at 6:33 Comment(0)
I
0

I think this is a typical path problem. You need to fix your environment variable PATH for npm to execute correctly.

the path you need to add looks like: C:\Program Files\nodejs\node_modules\npm\bin

Find the PATH env var and add the path you expect your npm packages to install from!

Or you can navigate to that directory and execute: npm config set prefix

Ironware answered 23/7, 2021 at 6:57 Comment(0)
A
0

Nodemon is looking for the main config in the package.json, Which may be missing. try to add main property in package.json with the key of your entry file. for example:-

"main":"src/main.ts"
Ankney answered 9/3, 2022 at 10:9 Comment(0)
M
0

"start": "nodemon src/app.js"

Matrimony answered 15/5, 2022 at 10:46 Comment(0)
C
0

Uninstall current nodemon and try to install nodemon globally, then run it again.

npm i nodemon -g

Coin answered 12/3, 2023 at 10:6 Comment(0)
E
0

Please check your parent folder name - the folder name or any file name should not contain any symbol like %^&*#$ if contains means this kind of error will occur

Emmi answered 4/1 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.