2

I'm trying to install mongoose on Mac OS X:

$ sudo npm install -g mongoose
npm http GET https://registry.npmjs.org/mongoose
npm http 304 https://registry.npmjs.org/mongoose
npm http GET https://registry.npmjs.org/hooks/0.2.1
npm http GET https://registry.npmjs.org/mongodb/1.1.11
npm http GET https://registry.npmjs.org/ms/0.1.0
npm http GET https://registry.npmjs.org/sliced/0.0.3
npm http 304 https://registry.npmjs.org/hooks/0.2.1
npm http 304 https://registry.npmjs.org/mongodb/1.1.11
npm http 304 https://registry.npmjs.org/ms/0.1.0
npm http 304 https://registry.npmjs.org/sliced/0.0.3
npm http GET https://registry.npmjs.org/bson/0.1.5
npm http 304 https://registry.npmjs.org/bson/0.1.5

> [email protected] install /usr/local/lib/node_modules/mongoose/node_modules/mongodb/node_modules/bson
> node install.js || (exit 0)

================================================================================
=                                                                              =
=  Attempting to build bson c++ extension                                      =
=   Windows: no build will be attempted as binaries are prepackaged            =
=   Unix: on failure the package will still install without the C++ extension  =
=                                                                              =
================================================================================
node-gyp clean
node-gyp configure build
  CXX(target) Release/obj.target/bson/ext/bson.o
  SOLINK_MODULE(target) Release/bson.node
  SOLINK_MODULE(target) Release/bson.node: Finished
child process exited with code 0
[email protected] /usr/local/lib/node_modules/mongoose
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])
$ node
> require('mongoose');
Error: Cannot find module 'mongoose'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at repl:1:1
    at REPLServer.self.eval (repl.js:111:21)
    at rli.on.e (repl.js:260:20)
    at REPLServer.self.eval (repl.js:118:5)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:93:17)

Shouldn't require work? Am I doing something wrong?

1
  • 2
    Try installing as your user, not as root. Also try installing without the global -g argument. Commented Oct 31, 2012 at 22:29

1 Answer 1

7

As per the npm FAQ:

I installed something globally, but I can't require() it

Install it locally.

The global install location is a place for command-line utilities to put their bins in the system PATH. It's not for use with require().

If you require() a module in your code, then that means it's a dependency, and a part of your program. You need to install it locally in your program.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.