'nodemon app crashed : Error code- MODULE_NOT_FOUND, requirestack: [ ]
When I am running nodemon run start it is giving me the following error I am running this on macos. Not sure if that matters or not. ERROR
node:internal/modules/cjs/loader:926
throw err;
^
Error: Cannot find module '/Users/jarvis/Documents/Backend/mongoTelusko/run'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
at Function.Module._load (node:internal/modules/cjs/loader:768:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...
This is my app.js file
const express = require('express')
const mongoose = require('mongoose')
const url = 'mongodb://localhost/AlienDBex'
enter code here
const app = express()
mongoose.connect(url, {useNewUrlParser: true})
const con = mongoose.connection
con.on('open', function(){
console.log('Connected...')
})
This is my package.json file
{
"name": "mongotelusko",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "nodemon app.js"
},
"author": "malay",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"mongodb": "^3.6.5",
"mongoose": "^5.12.2"
},
"devDependencies": {
"nodemon": "^2.0.7"
},
"description": ""
}
Solution 1:[1]
"scripts": {
"start": "nodemon app.js"
},
Since you have specified "start" script in package.json, npm start command automatically calls nodemon app.js
However, you can also run the nodemon app.js manually which also has the same effect.
Wrong: nodemon run start
Correct: nodemon app.js or npm start
Solution 2:[2]
You're running nodemon run start, which tells nodemon to execute run (run.js) with argument start. Did you mean to use npm run start? Hint: You can also use npm start as a shortcut.
Solution 3:[3]
I've got the same error while I'm trying to run the code on my Mac.
I found why it is showing me this error:
first reason is that I've installed Node.js through an installation pack downloaded from [nodejs.org][1], but I should've installed node from the Terminal.
second reason is that I found out that I was trying to run the file from a different folder. I was in folder
/users/practice/file-manager/frontend- trying to run the code from file which is located in directory/users/practice/file-manager/backend- the main reason which caused this error.
As a solution that worked for me:
- make sure you've installed Node.js from terminal
- make sure you're in the right directory when you're trying to run the
.jsfile.
Maybe this information helps you.
Solution 4:[4]
My solution after trying new files, etc... didnt work. Then starting from the beginning:
- deleting node.js and clearing cache about npm (from appdata)
- creating new file and being sure about path you can confirm with 'cd'
- trying to re-install npm_modules at my project folder.(npm install)
Then it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BryanRonnie |
| Solution 2 | Robert Kawecki |
| Solution 3 | Eugen |
| Solution 4 | ouflak |
