Tôi đang cố gắng cài đặt các gói NPM trên Ubuntu (12.04). Tôi đã cài đặt Node.js và NPM qua Chris Lea's PPA repository.Hành vi không nhất quán khi cài đặt các gói NPM trên toàn cầu
Tôi đang cố triển khai Uptime project vào máy chủ của mình. Tôi đã nhân bản ứng dụng từ GitHub, sau đó cố gắng cài đặt các ứng dụng phụ thuộc như một người dùng root:
[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])
Tất cả các giao diện đều được cài đặt thành công. Tuy nhiên, khi tôi đang kiểm tra nếu các gói phụ thuộc NPM được đáp ứng, tôi nhận được một loạt các phụ thuộc không được đáp ứng niêm yết, như tôi thậm chí không cài đặt chúng chỉ một giây trước:
[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
Theo như tôi biết (nhưng sửa tôi nếu tôi sai) NPM tôn trọng biến môi trường NODE_PATH
khi cài đặt các gói trên toàn cầu. Vui vẻ nếu bạn nhìn vào đầu ra cài đặt gói ở trên, bạn có thể thấy rằng NPM đã cài đặt các gói phụ thuộc toàn cầu vào /usr/lib/node_modules
. Nếu tôi kiểm tra lại các biến môi trường NODE_PATH
, nó quay ra rằng biến NODE_PATH
được thiết lập khác nhau:
[email protected]:/web/my-application# echo $NODE_PATH
/usr/lib/nodejs:/usr/share/javascript
Một điều cần làm rõ: Tôi không biết làm thế nào biến NODE_PATH
đã được thiết lập, tôi đã không thiết lập nó bản thân tôi và tôi có cảm giác rằng nó đi kèm với gói Ubuntu khi tôi cài đặt Node và NPM.
Sau đó, tôi quyết định thành lập một cách rõ ràng NODE_PATH
biến và kiểm tra gấp đôi so với phụ thuộc:
[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
Vẫn không thành công, tuy nhiên khi tôi đang cố gắng để chạy các ứng dụng với nút, nó khởi tạo thành công và chạy:
[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 }
Điều này có vẻ như sẽ ổn thôi, tuy nhiên tôi chắc chắn sẽ không chạy ứng dụng dưới dạng gốc nên tôi sẽ cần các gói NPM toàn cầu được công nhận khi tôi chạy ứng dụng người dùng.
Tôi có cảm giác rằng NPM có một số hành vi không nhất quán khi cài đặt gói. Khi cài đặt trên toàn cầu, nó chạy thành công nhưng sau đó nó không thể truy xuất chúng sau đó.
Tôi có thể làm gì và cũng có thể, biến môi trường của NODE_PATH
trông như thế nào?
Tôi nghĩ rằng đây sẽ là câu trả lời được chấp nhận vì nó giải quyết vấn đề của tôi. Chỉ cần đi vào thư mục của mô-đun của bạn và cài đặt phụ thuộc trong đó. – Carlton
xin lỗi tôi đã mất một thời gian để quay lại stackoverflow. xác nhận và chấp nhận câu trả lời. cảm ơn pentaur. –