10

I have a problem with npm install, in that it won't install @types.

This works fine

npm install --save lodash

However asking for types does not

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 (git@github.com:types/lodash)
npm ERR! git clone git@github.com: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 git@github.com:types/lodash Host key verification failed.
npm ERR! git clone git@github.com:types/lodash fatal: Could not read from remote repository.
npm ERR! git clone git@github.com:types/lodash
npm ERR! git clone git@github.com:types/lodash Please make sure you have the correct access rights
npm ERR! git clone git@github.com: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>

This has got me scratching my head. I've updated Chocolatey, NodeJS, NPM to make sure their own the latest versions. Tried the commands on empty folders or an existing TypeScript project - thinking it might be getting confused being ran within a Git repository (error: remote.origin.url). Looking at the GitHub URL it makes no sense git://github.com/types/lodash

I took these examples from MSDN Blog - The Future of Declaration Files

Update: I've uninstalled Node.js and tried reinstalling v6.11.3 LTS or v8.6.0. However the @types command still fails.

Update 2: I've realised Chocolately was masking the npm version. I removed the Chocolately folder, and upgraded npm as per @Louis answer.

5
  • It looks like you are required to have a github account with a private key configured in order to make it work.
    – lilezek
    Oct 2, 2017 at 15:17
  • 1
    Yes, but the URL itself is wrong github.com/types/lodash???
    – wonea
    Oct 2, 2017 at 15:42
  • 1
    Works fine for me, have you tried to update npm? Oct 2, 2017 at 16:13
  • 1
    Try to downgrade.
    – lilezek
    Oct 2, 2017 at 16:33
  • When all else fails, delete node_modules/ and then npm install
    – Chase
    Oct 3, 2017 at 9:21

1 Answer 1

4
+100

Upgrade your npm version to version 4 or 5. I'm mentioning 4 because I ran into problems with 5, and using 4 is still viable. I don't know of any good reason to run an older version.

You are using npm version 1.4.9, as shown in this line of the log:

npm ERR! npm -v 1.4.9

The problem is that npm versions prior to version 2 do not support scoped packages. Packages that begin with an @ are scoped packages, so @types/lodash is a scoped package. You need npm version 2 or greater to install it. If you were to use the latest npm in the 1.x series (1.4.29), you'd get a better error message:

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

Version 1.4.9 did not even know that scoped packages were a thing, so it cannot give a nice error message. It looks like it took the @ symbol as signifying that the package name is an address and filled in the missing information with Github as the default host.

The upgrade command I typically use to upgrade npm is:

npm install -g npm

You can specify a specific version by replacing the npm argument with one that gives specific version number. npm@4, for instance, would install the latest npm in the 4.x series. If you don't specify a version number, you get the latest released version.

1
  • Also note to install typings in devDependencies Oct 16, 2017 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.