【问题标题】:NPM fails to install typesNPM 无法安装类型
【发布时间】:2017-10-02 15:15:37
【问题描述】:

我有一个关于 npm install 的问题,因为它不会安装 @types。

这很好用

npm install --save lodash

但是不要求类型

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>

这让我摸不着头脑。我更新了 Chocolatey、NodeJS、NPM 以确保他们自己的最新版本。在空文件夹或现有 TypeScript 项目上尝试了命令 - 认为在 Git 存储库中运行可能会感到困惑(错误:remote.origin.url)。查看 GitHub URL 没有意义 git://github.com/types/lodash

我从MSDN Blog - The Future of Declaration Files中获取了这些示例

更新:我已卸载 Node.js 并尝试重新安装 v6.11.3 LTS 或 v8.6.0。但是@types 命令仍然失败。

更新 2:我意识到 Chocolately 掩盖了 npm 版本。我删除了 Chocolately 文件夹,并按照@Louis 的回答升级了 npm。

【问题讨论】:

  • 看起来你需要有一个配置了私钥的 github 帐户才能使其工作。
  • 是的,但是URL本身是错误的github.com/types/lodash???
  • 对我来说很好用,你试过更新 npm 吗?
  • 尝试降级。
  • 当一切都失败时,删除node_modules/,然后删除npm install

标签: node.js npm windows-10 npm-install


【解决方案1】:

将您的 npm 版本升级到版本 4 或 5。我提到 4 是因为我遇到了 5 的问题,并且使用 4 仍然可行。我不知道有什么好的理由运行旧版本。

您使用的是npm 1.4.9 版本,如日志这行所示:

npm ERR! npm -v 1.4.9

问题在于 npm 版本 2 之前的版本不支持作用域包。以@ 开头的包是作用域包,所以@types/lodash 是作用域包。您需要 npm 版本 2 或更高版本来安装它。如果您要使用 1.x 系列 (1.4.29) 中最新的 npm,您会收到更好的错误消息:

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

1.4.9 版甚至不知道作用域包是一个东西,所以它不能给出一个很好的错误消息。看起来它使用了@ 符号表示包名是一个地址,并以 Github 作为默认主机填充了缺失的信息。

我通常用来升级npm的升级命令是:

npm install -g npm

您可以通过将npm 参数替换为提供特定版本号的参数来指定特定版本。例如,npm@4 将安装 4.x 系列中最新的npm。如果您不指定版本号,您将获得最新发布的版本。

【讨论】:

  • 还要注意在devDependencies中安装类型
猜你喜欢
  • 2016-06-10
  • 1970-01-01
  • 2015-12-07
  • 1970-01-01
  • 1970-01-01
  • 2018-12-07
  • 2017-12-12
  • 2016-02-06
相关资源
最近更新 更多