Encountering a missing module error when attempting to start my Node.js application
I’m really frustrated with an issue that just came up today. My Node.js application was running smoothly until I hit ctrl+c to halt the server, and now when I try to run it again, I keep getting these error messages indicating that modules are missing.
I’ve already run npm install and rebooted my computer, but unfortunately, nothing seems to fix it. The issue arises immediately when I attempt to start the app.
This is the output I get in the console:
Mikes-MacBook:myproject mike$ npm start
> [email protected] start /Users/mike/myproject
> node ./server/index.js
module.js:328
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/mike/myproject/server.js:5:15)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.4.2
npm ERR! npm v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node ./server/index.js`
npm ERR! Exit status 1
npm ERR! Failed at the [email protected] start script.
Does anyone have any insights on what might be causing this? I’m quite baffled since everything was functioning properly before.
your package.json is probably pointing to the wrong entry file. the error shows node ./server/index.js but the stack trace mentions /server.js. check your main file path in package.json or try running node server.js directly to see if it works.
It seems likely that your node_modules directory may have been corrupted or inadvertently deleted. Another possibility is running npm install from the incorrect folder. Ensure that you are in the project root directory where your package.json file is located, and verify that express is included in the dependencies. If express is not listed, you can add it by running npm install express --save. If everything appears correct in package.json, consider deleting the entire node_modules folder and package-lock.json file, then running npm install again. This issue can arise after force-stopping Node processes, and performing a clean reinstall often resolves it. Always double-check that you are in the correct directory before executing npm commands.
Had the exact same nightmare on a big project last year. It’s all about dependency management chaos.
Stop manually fixing npm modules every time they break - you’re just burning time. I fought this until I automated my entire dev environment setup.
You need a workflow that handles dependencies, environment setup, and deployment automatically. No more guessing if you’re in the right directory or dealing with corrupted node_modules.
I use Latenode for automated workflows that check project state, install dependencies in order, and restart services when things break. It hooks into GitHub, watches repo changes, and triggers npm installs or environment resets automatically.
Once it’s set up, dependency issues disappear. Your dev environment just works.
Ditch the manual npm fighting and automate everything: https://latenode.com
The file path mismatch is your problem. Your npm start runs node ./server/index.js but the error points to /Users/mike/myproject/server.js - totally different files. I’ve hit this exact issue when restructuring projects and forgetting to update package.json scripts. You’re trying to load server/index.js which probably doesn’t exist or has different dependencies than server.js. Check if both files exist and see which one has your actual app code. Then either fix your package.json start script or rename your files to match. That’s why npm install didn’t work - the dependencies are there, you’re just running the wrong entry point.
This happened to me when I accidentally ran npm install with different Node versions on the same project. Check your Node version with node --version and compare it to what you used before. Switching Node versions often breaks native modules or makes dependencies incompatible. Also check if any global packages are conflicting - I’ve seen global express installations mess with local ones. Run npm ls to see your dependency tree and spot missing or broken links. If you’re using nvm, make sure you’re on the same Node version from when the project was working.