我試圖在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。 –