2017-10-02 2 views
9

Ich habe ein Problem mit npm install, da es @ types nicht installiert.NPM kann keine Typen installieren

Dies funktioniert

npm install --save lodash 

jedoch für Typen fragen nicht

npm install --save @types/lodash 

PS C:\Development\Temp> npm install --save @types/lodash 
npm WARN `git config --get remote.origin.url` returned wrong result (git://github.com/types/lodash) 
npm WARN `git config --get remote.origin.url` returned wrong result ([email protected]:types/lodash) 
npm ERR! git clone [email protected]:types/lodash Cloning into bare repository 'C:\Users\myuser\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-lodash-9eb5372a'... 
npm ERR! git clone [email protected]:types/lodash Host key verification failed. 
npm ERR! git clone [email protected]:types/lodash fatal: Could not read from remote repository. 
npm ERR! git clone [email protected]:types/lodash 
npm ERR! git clone [email protected]:types/lodash Please make sure you have the correct access rights 
npm ERR! git clone [email protected]:types/lodash and the repository exists. 
npm ERR! addLocal Could not install types/lodash 
npm ERR! Error: ENOENT: no such file or directory, stat 'C:\Development\Temp\types\lodash' 
npm ERR! If you need help, you may report this *entire* log, 
npm ERR! including the npm and node versions, at: 
npm ERR!  <http://github.com/npm/npm/issues> 

npm ERR! System Windows_NT 10.0.15063 
npm ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "@types/lodash" 
npm ERR! cwd C:\Development\Temp 
npm ERR! node -v v8.6.0 
npm ERR! npm -v 1.4.9 
npm ERR! path C:\Development\Temp\types\lodash 
npm ERR! syscall stat 
npm ERR! code ENOENT 
npm ERR! errno -4058 
npm ERR! 
npm ERR! Additional logging details can be found in: 
npm ERR!  C:\Development\Temp\npm-debug.log 
npm ERR! not ok code 0 
PS C:\Development\Temp> 

Dies hat mir meinen Kopf kratzen. Ich habe Chocolatey, NodeJS, NPM aktualisiert, um sicherzustellen, dass sie die neuesten Versionen besitzen. Versuchte die Befehle in leeren Ordnern oder einem vorhandenen TypeScript-Projekt - es könnte sein, dass es verwirrt wird, wenn es in einem Git-Repository ausgeführt wird (Fehler: remote.origin.url). Mit Blick auf die GitHub URL es keinen Sinn macht git: //github.com/types/lodash

ich diese Beispiele aus MSDN Blog - The Future of Declaration Files nahm

Update: Ich habe Node.js deinstalliert und versucht v6.11.3 LTS Neuinstallation oder v8.6.0. Der Befehl @types schlägt jedoch immer noch fehl.

Update 2: Ich habe festgestellt, dass Chocolately die npm-Version maskiert hat. Ich entfernte den Chocolatly-Ordner und rüstete npm laut @Louis-Antwort auf.

+0

Es sieht so aus, als ob Sie einen GitHub-Account mit einem privaten Schlüssel benötigen, der konfiguriert ist, damit er funktioniert. – lilezek

+1

Ja, aber die URL selbst ist falsch github.com/types/lodash ??? – wonea

+1

Funktioniert gut für mich, haben Sie versucht, npm zu aktualisieren? –

Antwort

4

Aktualisieren Sie Ihre npm Version auf Version 4 oder 5. Ich erwähne 4, weil ich Probleme mit 5 hatte, und die Verwendung von 4 ist immer noch machbar. Ich kenne keinen guten Grund, eine ältere Version zu verwenden.

Sie verwenden npm Version 1.4.9, wie sie in dieser Zeile des Protokolls gezeigt:

npm ERR! npm -v 1.4.9 

Das Problem ist, dass npm Versionen vor Version 2 nicht scoped Pakete unterstützen. Pakete, die mit @ beginnen, sind Pakete mit Gültigkeitsbereich, daher ist @types/lodash ein Gültigkeitsbereichspaket. Sie benötigen npm Version 2 oder höher, um es zu installieren. Wenn Sie die neuesten npm in der 1.x-Serie verwenden sind (1.4.29), dann würden Sie eine bessere Fehlermeldung:

npm ERR! Error: This version of npm doesn't support scoped packages (caused by reference to @types/lodash). Update to [email protected]+. 

Version 1.4.9 noch nicht einmal wissen, dass scoped Pakete eine Sache waren , also kann es keine nette Fehlermeldung geben. Es sieht so aus, als ob das Symbol @ bedeutet, dass der Paketname eine Adresse ist und die fehlenden Informationen mit Github als Standardhost ausgefüllt wurden.

Der Upgrade-Befehl, den ich normalerweise npm Upgrade verwenden ist:

npm install -g npm 

Sie eine bestimmte Version mit einem durch Ersetzen des npm Argument angeben können, die bestimmte Versionsnummer gibt. [email protected] zum Beispiel würde die neuesten npm in der 4.x-Serie installieren. Wenn Sie keine Versionsnummer angeben, erhalten Sie die neueste veröffentlichte Version.

+0

Beachten Sie auch, um Typisierungen in' devDependencies' zu installieren –