2

我正在尝试在 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

> bson@0.1.5 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
mongoose@3.3.1 /usr/local/lib/node_modules/mongoose
├── sliced@0.0.3
├── hooks@0.2.1
├── ms@0.1.0
└── mongodb@1.1.11 (bson@0.1.5)
$ 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)

不应该require工作吗?难道我做错了什么?

4

1 回答 1

7

根据npm 常见问题解答

我在全球范围内安装了一些东西,但我不能 require() 它

在本地安装它。

全局安装位置是命令行实用程序将其 bin 放入系统的位置PATH。它不适用于require().

如果您require()的代码中有一个模块,那么这意味着它是一个依赖项,并且是您程序的一部分。您需要在程序中本地安装它。

于 2012-10-31T23:11:21.137 回答