【问题标题】:Installing mongoose on node在节点上安装猫鼬
【发布时间】:2012-10-21 12:35:01
【问题描述】:

我正在尝试在 Mac OS X 上安装 mongoose:

$ 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 不应该工作吗?我是不是做错了什么?

【问题讨论】:

  • 尝试以您的用户身份安装,而不是以 root 身份安装。还可以尝试不使用全局 -g 参数进行安装。

标签: node.js mongodb mongoose npm


【解决方案1】:

根据npm FAQ

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

在本地安装。

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

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

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-26
  • 2018-12-16
  • 1970-01-01
  • 2016-01-01
  • 1970-01-01
  • 2015-08-28
相关资源
最近更新 更多