我试图在Ubuntu(12.04)上安装NPM软件包。我已经通过Chris Lea's PPA repository安装了Node.js和NPM。全局安装NPM软件包时的行为不一致
我试图将Uptime project部署到我的服务器。我已经克隆了GitHub上的应用程序,然后试图安装该应用程序依赖作为根用户:
[email protected]:/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
> [email protected] 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
> [email protected] 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> =
= =
================================================================================
[email protected] /usr/lib/node_modules/node-uptime
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])
所有好看的包似乎成功安装。然而,当我检查,如果NPM软件包的依赖关系得到满足,我收到了一堆满足的依赖关系的上市,就像我没有哪怕只是一秒钟前安装:
[email protected]:/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
[email protected] /web/my-application
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── UNMET DEPENDENCY mongoose 2.5.11
└─┬ [email protected]
├── [email protected]
├── [email protected]
└─┬ [email protected]
├── 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
变量设置不同:
[email protected]:/web/my-application# echo $NODE_PATH
/usr/lib/nodejs:/usr/share/javascript
一件事澄清:我不知道该怎么NODE_PATH
变量已定,我没有把它设置我自己,我有一种感觉,当我安装Node和NPM时,它带有Ubuntu软件包。
然后,我决定明确设置NODE_PATH
变量,并仔细检查相关性:
[email protected]:/web/my-application# export NODE_PATH=/usr/lib/node_modules
[email protected]:/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
[email protected] /web/my-application
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── UNMET DEPENDENCY mongoose 2.5.11
└─┬ [email protected]
├── [email protected]
├── [email protected]
└─┬ [email protected]
├── 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
仍然没有成功,但是当我试图运行与节点的应用程序,它成功地初始化并运行:
[email protected]:/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 }
这看起来将是确定从现在开始,但是我绝对不会去运行应用程序的根,所以我需要在全球NPM包被认可的时候,我会运行的应用程序作为专用用户。
我有一种感觉,NPM在安装软件包时有某种不一致的行为。全局安装时,它会成功运行,但之后无法检索。
我该怎么办,还有,NODE_PATH
环境变量如何看起来像?
我想这应该是公认的答案,因为它解决了我的问题。只要进入你的模块的文件夹,并在那里安装依赖。 – Carlton
对不起,我花了一段时间才回到了stackoverflow。确认并接受了答案。感谢pentaur。 –