11

I'm building a basic MEAN webapp and am new to the stack. I have the front end running, but as soon as I add the following lines to app.js:

var mongoose = require('mongoose');
require('./models/test');
mongoose.connect('mongodb://localhost:3000/design-data-test');

I get the following error in terminal:

Error: Cannot find module 'debug'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/username/node_modules/mongoose/node_modules/mquery/lib/mquery.js:11:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

And all of my front end code stops running. Mongodb is running on the default port.

How would I go about resolving this error?

Carriemf
  • 159
  • 1
  • 3
  • 12
  • 1
    Try to install `npm install debug --save-dev` module – Artem Baranovskii Aug 05 '15 at 13:34
  • But `debug` module already exists in `mquery` module https://github.com/aheckmann/mquery/blob/master/package.json#L15 Try to reinstall `mongoose` module and ensure that this is no errors. – Artem Baranovskii Aug 05 '15 at 13:37
  • @ArtemBaranovskii, that would've been a nice fix, but I'm still getting the same error. Any other suggestions? – Carriemf Aug 05 '15 at 13:40
  • Could you check existance of `/Users/username/node_modules/mongoose/node_modules/mquery/node_modules/debug` folder? – Artem Baranovskii Aug 05 '15 at 13:45
  • Just did. Moved the debug folder there and the previous error. I now have this error. – Carriemf Aug 05 '15 at 13:46
  • Error: Cannot find module 'debug' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (/Users/username/design-data/node_modules/express/node_modules/finalhandler/index.js:14:13) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) – Carriemf Aug 05 '15 at 13:46
  • did you install your packages into `/Users/username/design-data` folder or in `/Users/username/` one? And where your start point script is resided? – Artem Baranovskii Aug 05 '15 at 13:49
  • The packages were originally installed globally, then I used the express generator to build a skeleton and install the dependencies to the design-data/node-modules error – Carriemf Aug 05 '15 at 13:50
  • You have to avoid installing packages globally. You should install it in your project folder. The error you've provided might due access rights. Because installation of modules globally requires administrator privileges. – Artem Baranovskii Aug 05 '15 at 13:54
  • To correctly install packages you need to move to your project folder (where your `package.json` file resides) and execute `npm install` command. http://expressjs.com/starter/generator.html Search for `Then install dependencies` – Artem Baranovskii Aug 05 '15 at 13:56

2 Answers2

6

For future visitors: You are probably missing a dependency. Make sure you run this first:

npm install

... before you run your app with npm start or node <app>

Voicu
  • 16,921
  • 10
  • 60
  • 69
1

I think this may happen if you have a child dependency on debug through another package (for example express or mongoose) but you did not provide the dependencies' package.json files with the deployed application which makes node.js unable to locate debug.

GeirGrusom
  • 999
  • 5
  • 18