Próbuję zainstalować pakiety NPM w systemie Ubuntu (12.04). Zainstalowałem Node.js i NPM przez Chris Lea's PPA repository.Niespójne zachowanie podczas instalowania pakietów NPM na całym świecie
Próbuję wdrożyć Uptime project na mój serwer. Mam sklonowany aplikację z GitHub, a następnie próbuje zainstalować zależności aplikacji jako użytkownik 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])
Wszystko wygląda dobrze, pakiety wydają się być zainstalowana pomyślnie. Jednak kiedy jestem sprawdzenie, czy spełnione są zależności pakietów KMP, Dostaję kilka niespełnionych zależnościach na liście, jak ja nawet nie instalować je tylko sekundy temu:
[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
O ile wiem, (ale popraw mnie, jeśli się mylę) NPM respektuje zmienną środowiskową NODE_PATH
podczas instalowania pakietów na całym świecie. Jeśli spojrzysz na dane wyjściowe instalacji pakietów powyżej, możesz zobaczyć, że NPM zainstalował zależne pakiety globalnie w /usr/lib/node_modules
. Gdybym dokładnie sprawdzić zmienną środowiskową z NODE_PATH
, okazuje się, że zmienna NODE_PATH
jest ustawiony inaczej:
[email protected]:/web/my-application# echo $NODE_PATH
/usr/lib/nodejs:/usr/share/javascript
Jedno wyjaśnienie: Nie wiem, jak zmienna NODE_PATH
został ustawiony, nie mam ustawić go ja i mam wrażenie, że przyszedł z pakietem Ubuntu, gdy zainstalowałem Node i NPM.
Potem postanowił jawnie ustawić NODE_PATH
zmienne i dokładnie sprawdzić zależności:
[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
nadal nie sukces, jednak gdy próbuję uruchomić aplikację z węzła, to z powodzeniem inicjuje i biegnie:
[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 }
to wygląda to będzie od teraz OK, jednak ja na pewno nie zamierza uruchomić aplikację jako root, więc będę potrzebował globalne pakiety KMP zostać rozpoznany, kiedy będę uruchomić aplikację jako dedykowany użytkownik.
Mam wrażenie, że NPM ma jakieś niespójne zachowanie podczas instalowania pakietów. Podczas instalacji globalnej działa poprawnie, ale później nie może ich odzyskać.
Co mogę zrobić, a także, jak wygląda zmienna środowiskowa NODE_PATH
?
myślę, że to powinno być przyjętej odpowiedź jak to rozwiązać mój problem. Po prostu przejdź do folderu modułu i zainstaluj zależność tam. – Carlton
Przepraszam, że zajęło mi trochę czasu, aby wrócić do stackoverflow. potwierdził i przyjął odpowiedź. dzięki pentaur. –