Node.js NPM安装表达错误获取失败 [英] Node.js npm install express error fetch failed

查看:56
本文介绍了Node.js NPM安装表达错误获取失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm install express结果出现以下错误

npm install express results in the following error

$ npm install express
npm ERR! fetch failed https://registry.npmjs.org/debug/-/debug-2.1.0.tgz
npm ERR! fetch failed https://registry.npmjs.org/etag/-/etag-1.5.1.tgz
npm ERR! fetch failed https://registry.npmjs.org/methods/-/methods-1.1.0.tgz
npm ERR! fetch failed https://registry.npmjs.org/on-finished/-/on-finished-2.1.1.tgz
npm ERR! fetch failed https://registry.npmjs.org/debug/-/debug-2.1.0.tgz
npm ERR! fetch failed https://registry.npmjs.org/debug/-/debug-2.1.0.tgz
npm ERR! Error: Hostname/IP doesn't match certificate's altnames
npm ERR!     at SecurePair.<anonymous> (tls.js:1389:23)
npm ERR!     at SecurePair.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:979:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:471:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:340:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:368:25)
npm ERR!     at doWrite (_stream_writable.js:225:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:215:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:182:11)
npm ERR!     at write (_stream_readable.js:601:24)
npm ERR!     at flow (_stream_readable.js:610:7)
npm ERR!     at Socket.pipeOnReadable (_stream_readable.js:642:5)
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 Linux 3.14.13-c9
npm ERR! command "/home/ubuntu/.nvm/v0.10.33/bin/node" "/home/ubuntu/.nvm/v0.10.33/bin/npm" "install" "express"
npm ERR! cwd /home/ubuntu/workspace
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! not ok code 0

该如何解决?这个问题的答案已经有很多重复了,答案不正确,我与下面的正确答案分享了这个问题,以解决问题.

How to resolve this? There are already many duplicates of this question with INCORRECT answers, I'm sharing this with the below CORRECT answer to clear things up.

推荐答案

潜在的问题(对我和其他人而言)是npm本身的过时版本

The underlying problem (for me and many others) is an outdated version of npm itself

$ npm version
{ http_parser: '1.0',
  node: '0.10.33',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
  uv: '0.10.29',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1j',
  npm: '1.4.28' }

在撰写本文时,npm的最新版本是2.1.6,因此1.4.28已过时.只需运行

Latest version of npm at time of writing is 2.1.6, so 1.4.28 is outdated. Simply run

$ npm install npm -g
/home/ubuntu/.nvm/v0.10.33/bin/npm -> /home/ubuntu/.nvm/v0.10.33/lib/node_modules/npm/bin/npm-cli.js
npm@2.1.11 /home/ubuntu/.nvm/v0.10.33/lib/node_modules/npm

在那之后,npm install express可以正常工作了.

After that npm install express works fine.

$ npm install express
express@4.10.5 node_modules/express
├── utils-merge@1.0.0
├── merge-descriptors@0.0.2
├── fresh@0.2.4
├── cookie@0.1.2
├── escape-html@1.0.1
├── range-parser@1.0.2
├── cookie-signature@1.0.5
├── finalhandler@0.3.2
├── vary@1.0.0
├── media-typer@0.3.0
├── parseurl@1.3.0
├── methods@1.1.0
├── serve-static@1.7.1
├── content-disposition@0.5.0
├── path-to-regexp@0.1.3
├── depd@1.0.0
├── qs@2.3.3
├── etag@1.5.1 (crc@3.2.1)
├── on-finished@2.1.1 (ee-first@1.1.0)
├── debug@2.1.0 (ms@0.6.2)
├── send@0.10.1 (destroy@1.0.3, ms@0.6.2, mime@1.2.11)
├── accepts@1.1.4 (negotiator@0.4.9, mime-types@2.0.4)
├── type-is@1.5.4 (mime-types@2.0.4)
└── proxy-addr@1.0.4 (forwarded@0.1.0, ipaddr.js@0.1.5)

很多人认为问题是SSL证书无法正确识别,因此建议使用以下错误的证书,并且不应使用,因为它们会导致获取时使用不安全的连接:

Lots of people think the problem is SSL certificates not being recognized properly, thus and recommend the following which is WRONG and should NOT be used as they result in unsecure connection used when fetching:

在npm install express之前运行npm配置设置注册表 http://registry.npmjs.org/或npmconfig set strict-ssl false

before npm install express run npm config set registry http://registry.npmjs.org/ OR npm config set strict-ssl false

这篇关于Node.js NPM安装表达错误获取失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆