2012-06-03 3 views
6

Sto cercando di installare i pacchetti NPM su Ubuntu (12.04). Ho installato Node.js e NPM tramite Chris Lea's PPA repository.Comportamento incoerente durante l'installazione globale dei pacchetti NPM

Sto provando a distribuire il Uptime project al mio server. Ho clonato l'applicazione dal GitHub, poi cercando di installare le dipendenze di applicazioni come utente 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]) 

Tutto guardando bene, i pacchetti sembrano essere installato con successo. Tuttavia, quando sto controllando se sono soddisfatte le dipendenze del pacchetto di NPM, sto ricevendo un sacco di dipendenze non soddisfatte elencati, come non ho nemmeno installare loro solo un secondo fa:

[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 

Per quanto ne so (ma correggimi se sbaglio) NPM rispetta la variabile di ambiente NODE_PATH quando si installano i pacchetti a livello globale. Stranamente se si guarda l'output di installazione del pacchetto sopra, è possibile vedere che NPM ha installato pacchetti dipendenti a livello globale in /usr/lib/node_modules. Se io doppio controllo la variabile d'ambiente NODE_PATH, si scopre che la variabile NODE_PATH è impostata in modo diverso:

[email protected]:/web/my-application# echo $NODE_PATH 
/usr/lib/nodejs:/usr/share/javascript 

Una cosa da chiarire: io non so come è stata impostata la variabile NODE_PATH, non l'ho impostarla me stesso e ho la sensazione che sia arrivato con il pacchetto Ubuntu quando ho installato Node e NPM.

Poi ho deciso di impostare in modo esplicito i NODE_PATH variabili e doppio controllo le dipendenze:

[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 

Ancora senza successo, ma quando sto cercando di eseguire l'applicazione con il nodo, inizializza e corre con successo:

Sembra che sarà OK da ora, tuttavia non ho intenzione di eseguire l'applicazione come root, quindi avrò bisogno dei pacchetti NPM globali per essere riconosciuto quando eseguirò l'app come utente.

Ho la sensazione che NPM abbia una sorta di comportamento inconsistente durante l'installazione dei pacchetti. Durante l'installazione a livello globale, viene eseguito correttamente, ma in seguito non riesce a recuperarli.

Cosa posso fare, e anche, come fa la variabile d'ambiente NODE_PATH come?

risposta

5

È necessario installarlo con solo npm install -d, senza -g. I requisiti dei pacchetti sono locali per ogni pacchetto (in modo da avere node_modules\a quando si dipende da a e node_modules\a\node_modules\b, quando a dipende da).

Vedere http://npmjs.org/doc/faq.html#I-installed-something-globally-but-I-can-t-require-it per ulteriori dettagli.

+0

credo che questo dovrebbe essere la risposta accettata come ha risolto il mio problema. Basta andare nella cartella del modulo e installare la dipendenza in là. – Carlton

+0

scusate, mi ci è voluto un po 'per tornare allo stackoverflow. confermato e accettato la risposta. grazie pentaur. –

-2

Per me è risolto utilizzando il comando qui sotto -

npm installare [email protected] -d.4 --registry http://registry.npmjs.org/

+0

questo deve essere un bug in 'npm', sicuramente il passaggio nel registro predefinito non dovrebbe avere un effetto sul modo in cui le cose sono installate. Mi dispiace ma non ho intenzione di votare questa risposta in quanto non spiega perché il mio tentativo di cui sopra non ha funzionato. –

2

svuotare la cache ha lavorato per me

npm cache clean