3

I'm using Visual Studio with node.js tools. My project won't start up and it's throwing the error.

Error: Cannot find module 'mongodb'

This is a package I had previously installed, I figured maybe the global package directory might be a useful place to look, does anyone know where this is located?

I've narrowed it down to when I

require('mongoose')

I have the mongoose package, I have mongodb installed (correctly I think, and not the package but the actual thing, this stuff confuses the hell out of me), so not sure why it's complaining.

Ally
  • 4,894
  • 8
  • 37
  • 45
  • possible duplicate of [node.js cannot find module 'mongodb'](http://stackoverflow.com/questions/14226410/node-js-cannot-find-module-mongodb) – T J Nov 25 '14 at 16:53

1 Answers1

10

Quick Fix:

The mongoose package.json file lists mongodb as a dependency. The mongodb package will be in the mongoose package's node_modules directory. This won't be a global install problem...

The easiest fix to try is to run this in the project's root directory:

npm install mongoose

If you require a specific version of mongoose, use this format:

npm install mongoose@x.y.z

...where x.y.z is the version, like 3.8.8.

If the Quick Fix Fails

There's a good chance that the mongodb build failed during mongoose installation and will fail again because of an incompatible Windows VisualStudio/SDK version or a missing Python dependency. This is based upon personal experience and from helping other Windows users with npm install failures...

If there are errors on a second try and they are from the mongodb build, the messages will usually be clear about what dependency isn't being met and what you can install to fix things. If not, you can check the node-gyp dependency requirements and verify you meet those requirements.

Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
Matthew Bakaitis
  • 11,600
  • 7
  • 43
  • 53
  • Thanks that's some useful steps, tried installing manually and hitting an error like `The imported project "C:\Microsoft.Cpp.Default.props" was not found`. I read somewhere that installing Visual Studio Express 2013 might help, after that a slightly different install error is shown `The build tools for Visual Studio 2010 cannot be found`. – Ally Mar 07 '14 at 23:40
  • 1
    Found the solution, you have to install with the option telling it to use 2012 tools e.g. `npm install --msvs_version=2012`, as outlined in [this answer](http://stackoverflow.com/questions/14180012/npm-install-for-some-packages-sqlite3-socket-io-fail-with-error-msb8020-on-wi). – Ally Mar 07 '14 at 23:52