6

我正在尝试在 Ubuntu (12.04) 上安装 NPM 包。我已经通过Chris Lea 的 PPA 存储库安装了 Node.js 和 NPM 。

我正在尝试将Uptime 项目部署到我的服务器。我已经从 GitHub 克隆了应用程序,然后尝试以 root 用户身份安装应用程序依赖项:

root@dev:/web/my-application# npm install -g
npm http GET https://registry.npmjs.org/mongoose/2.5.11
npm http GET https://registry.npmjs.org/express/2.5.0
npm http GET https://registry.npmjs.org/ejs/0.6.1
npm http GET https://registry.npmjs.org/config/0.4.11
npm http GET https://registry.npmjs.org/async/0.1.18
npm http GET https://registry.npmjs.org/socket.io/0.9.2
npm http 304 https://registry.npmjs.org/ejs/0.6.1
npm http 304 https://registry.npmjs.org/async/0.1.18
npm http 304 https://registry.npmjs.org/mongoose/2.5.11
npm http 304 https://registry.npmjs.org/express/2.5.0
npm http 304 https://registry.npmjs.org/config/0.4.11
npm http 304 https://registry.npmjs.org/socket.io/0.9.2
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/mkdirp/0.0.7
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/redis/0.6.7
npm http GET https://registry.npmjs.org/socket.io-client/0.9.2
npm http GET https://registry.npmjs.org/yaml
npm http GET https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/hooks/0.2.0
npm http GET https://registry.npmjs.org/mongodb/0.9.9-5
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/mkdirp/0.0.7
npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/redis/0.6.7
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.2
npm http 304 https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/yaml
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/hooks/0.2.0
npm http 304 https://registry.npmjs.org/mongodb/0.9.9-5
npm http GET https://registry.npmjs.org/eyes

> mongodb@0.9.9-5 install /usr/lib/node_modules/node-uptime/node_modules/mongoose/node_modules/mongodb
> node install.js

npm http 304 https://registry.npmjs.org/eyes
================================================================================
=                                                                              =
=  To install with C++ bson parser do <npm install mongodb --mongodb:native>   =
=                                                                              =
================================================================================
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http 304 https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/commander

> ws@0.4.16 install /usr/lib/node_modules/node-uptime/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> node install.js

================================================================================
=                                                                              =
=  To install WS with blazing fast native extensions, use                      =
=       <npm install ws --ws:native>                                           =
=                                                                              =
================================================================================
node-uptime@1.2.0 /usr/lib/node_modules/node-uptime
├── async@0.1.18
├── ejs@0.6.1
├── express@2.5.0 (mkdirp@0.0.7, mime@1.2.5, qs@0.5.0, connect@1.7.3)
├── mongoose@2.5.11 (hooks@0.2.0, mongodb@0.9.9-5)
├── config@0.4.11 (yaml@0.2.3, coffee-script@1.3.3, vows@0.5.13)
└── socket.io@0.9.2 (policyfile@0.0.4, redis@0.6.7, socket.io-client@0.9.2)

一切看起来都不错,这些软件包似乎已成功安装。但是,当我检查是否满足 NPM 包依赖项时,我会列出一堆未满足的依赖项,就像我一秒钟前甚至没有安装它们一样:

root@dev:/web/my-application# npm list
npm WARN mongoose 2.5.11 Unmet dependency in /web/my-application
npm WARN active-x-obfuscator 0.0.1 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN uglify-js 1.2.5 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN ws 0.4.x Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN xmlhttprequest 1.2.2 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
node-uptime@1.2.0 /web/my-application
├── async@0.1.18 
├─┬ config@0.4.11 
│ ├── coffee-script@1.3.3 
│ ├─┬ vows@0.5.13 
│ │ └── eyes@0.1.7 
│ └── yaml@0.2.3 
├── ejs@0.6.1 
├─┬ express@2.5.0 
│ ├── connect@1.7.3 
│ ├── mime@1.2.5 
│ ├── mkdirp@0.0.7 
│ └── qs@0.5.0 
├── UNMET DEPENDENCY mongoose 2.5.11
└─┬ socket.io@0.9.2 
  ├── policyfile@0.0.4 
  ├── redis@0.6.7 
  └─┬ socket.io-client@0.9.2 
    ├── UNMET DEPENDENCY active-x-obfuscator 0.0.1
    ├── UNMET DEPENDENCY uglify-js 1.2.5
    ├── UNMET DEPENDENCY ws 0.4.x
    └── UNMET DEPENDENCY xmlhttprequest 1.2.2

据我所知(但如果我错了,请纠正我)NPM 在NODE_PATH全局安装包时尊重环境变量。有趣的是,如果您查看上面的包安装输出,您可以看到 NPM 将依赖包全局安装到/usr/lib/node_modules. 如果我仔细检查NODE_PATH环境变量,事实证明该NODE_PATH变量的设置不同:

root@dev:/web/my-application# echo $NODE_PATH
/usr/lib/nodejs:/usr/share/javascript

需要澄清的一件事:我不知道NODE_PATH变量是如何设置的,我自己没有设置它,当我安装 Node 和 NPM 时,我感觉它是随 Ubuntu 包一起提供的。

然后我决定显式设置NODE_PATH变量并仔细检查依赖项:

root@dev:/web/my-application# export NODE_PATH=/usr/lib/node_modules
root@dev:/web/my-application# npm list
npm WARN mongoose 2.5.11 Unmet dependency in /web/my-application
npm WARN active-x-obfuscator 0.0.1 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN uglify-js 1.2.5 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN ws 0.4.x Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
npm WARN xmlhttprequest 1.2.2 Unmet dependency in /web/my-application/node_modules/socket.io/node_modules/socket.io-client
node-uptime@1.2.0 /web/my-application
├── async@0.1.18 
├─┬ config@0.4.11 
│ ├── coffee-script@1.3.3 
│ ├─┬ vows@0.5.13 
│ │ └── eyes@0.1.7 
│ └── yaml@0.2.3 
├── ejs@0.6.1 
├─┬ express@2.5.0 
│ ├── connect@1.7.3 
│ ├── mime@1.2.5 
│ ├── mkdirp@0.0.7 
│ └── qs@0.5.0 
├── UNMET DEPENDENCY mongoose 2.5.11
└─┬ socket.io@0.9.2 
  ├── policyfile@0.0.4 
  ├── redis@0.6.7 
  └─┬ socket.io-client@0.9.2 
    ├── UNMET DEPENDENCY active-x-obfuscator 0.0.1
    ├── UNMET DEPENDENCY uglify-js 1.2.5
    ├── UNMET DEPENDENCY ws 0.4.x
    └── UNMET DEPENDENCY xmlhttprequest 1.2.2

仍然没有成功,但是当我尝试使用节点运行应用程序时,它成功初始化并运行:

root@dev:/web/my-application# node app.js 
Monitor origin started
   info  - socket.io started
Express server listening on port 8082 in development mode
Mongoose: pings.ensureIndex({ timestamp: -1 }) {}  
Mongoose: checkevents.ensureIndex({ timestamp: -1, check: 1 }) {}  
Mongoose: checkhourlystats.ensureIndex({ timestamp: -1, check: 1 }) { unique: true }  
Mongoose: checkdailystats.ensureIndex({ timestamp: -1, check: 1 }) { unique: true }  
Mongoose: checkmonthlystats.ensureIndex({ timestamp: -1, check: 1 }) { unique: true }  
Mongoose: checks.find({ '$where': 'function () {\n if (this.isPaused) return false;\n if (!this.firstTested) return true;\n var delay = (this.lastTested.getTime() - this.firstTested.getTime()) % this.interval;\n return (Date.now() - this.lastTested.getTime() + delay) >= (this.interval || 60000);\n}' }) { fields: { qos: 0 }, safe: true }  
Mongoose: taghourlystats.ensureIndex({ timestamp: -1, name: 1 }) { unique: true }  
Mongoose: tagdailystats.ensureIndex({ timestamp: -1, name: 1 }) { unique: true }  
Mongoose: tagmonthlystats.ensureIndex({ timestamp: -1, name: 1 }) { unique: true }  
Mongoose: tags.ensureIndex({ name: 1 }) { unique: true }

这看起来从现在开始就可以了,但是我绝对不会以 root 身份运行应用程序,所以当我以专用用户身份运行应用程序时,我需要识别全局 NPM 包。

我感觉 NPM 在安装包时有某种不一致的行为。全局安装时,它运行成功,但之后无法检索它们。

我能做什么,以及一个人的NODE_PATH环境变量是什么样的?

4

3 回答 3

5

你必须安装它只是npm install -d,没有-g。包的要求对于每个包都是本地的(所以node_modules\a当你依赖时你有anode_modules\a\node_modules\ba依赖时你有b)。

有关更多详细信息,请参阅http://npmjs.org/doc/faq.html#I-installed-something-globally-but-I-can-t-require-it

于 2012-06-27T08:15:36.650 回答
2

清除缓存对我有用

npm cache clean
于 2016-06-25T23:19:07.240 回答
-2

对我来说,它是通过使用以下命令解决的 -

npm install -d kanso@0.3.4 --registry http://registry.npmjs.org/

于 2014-08-30T15:14:33.653 回答