我正在尝试按照 Express 网站指南中提到的说明在 Windows 终端中安装 Express
1 首先,我在 package.json 文件内创建了一个目录 Node 。
我的package.json如下
{
"name": "hello-world",
"description": "hello world test app",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x"
}
}
然后我尝试运行命令
npm install
但出现以下错误
E:\myFindings\nodejs_programs\node>npm install
npm http GET https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-3.4.8.tgz
npm ERR! Error: tunneling socket could not be established, cause=connect ETIMEDOUT
npm ERR! at ClientRequest.onError (C:\Program Files\nodejs\node_modules\npm\node_modules\request\tunnel.js:161:17)
npm ERR! at ClientRequest.g (events.js:185:14)
npm ERR! at ClientRequest.EventEmitter.emit (events.js:88:17)
npm ERR! at Socket.socketErrorListener (http.js:1320:9)
npm ERR! at Socket.EventEmitter.emit (events.js:88:17)
npm ERR! at Socket._destroy.self.errorEmitted (net.js:329:14)
npm ERR! at process.startup.processNextTick.process._tickCallback (node.js:244:9)
npm ERR! { [Error: tunneling socket could not be established, cause=connect ETIMEDOUT] code: 'ECONNRESET' }
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddb3adb0f09dbab2b2bab1b8baafb2a8adaef3beb2b0" rel="noreferrer noopener nofollow">[email protected]</a>>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd E:\myFindings\nodejs_programs\node
npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32
npm ERR! code ECONNRESET
npm ERR! message tunneling socket could not be established, cause=connect ETIMEDOUT
npm ERR! Error: socket hang up
npm ERR! at createHangUpError (http.js:1253:15)
npm ERR! at Socket.socketCloseListener (http.js:1304:23)
npm ERR! at Socket.EventEmitter.emit (events.js:88:17)
npm ERR! at Socket._destroy.destroyed (net.js:358:10)
npm ERR! at process.startup.processNextTick.process._tickCallback (node.js:244:9)
npm ERR! { [Error: socket hang up] code: 'ECONNRESET' }
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7d9c7da9af7d0d8d8d0dbd2d0c5d8c2c7c499d4d8da" rel="noreferrer noopener nofollow">[email protected]</a>>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd E:\myFindings\nodejs_programs\node
npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32
npm ERR! code ECONNRESET
npm ERR! message socket hang up
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! E:\myFindings\nodejs_programs\node\npm-debug.log
npm ERR! not ok code 0
我无法理解问题所在,请帮我解决
我什至尝试在不使用 .json 文件的情况下安装 Express,但遇到了相同的错误
我的 npm 配置列表的内容
E:\myFindings\nodejs_programs\node>npm config list
; cli configs
; userconfig C:\Users\sudipkumars\.npmrc
https-proxy = "http://sudip:sudip7@proxy:8086/"
proxy = "http://sudip:sudip7@proxy:8086/%20strict-ssl%20=%20false"
registry = "https://registry.npmjs.org/"
; builtin config C:\Program Files\nodejs\node_modules\npm\npmrc
prefix = "C:\\Users\\sudipkumars\\AppData\\Roaming\\npm"
; node install prefix = C:\Program Files
; node bin location = C:\Program Files\nodejs\\node.exe
; cwd = E:\myFindings\nodejs_programs\node
; HOME = C:\Users\sudipkumars
; 'npm config ls -l' to show all defaults.
我尝试了你的建议
npm config set registry http://registry.npmjs.org/
输出是
E:\myFindings\nodejs_programs\node>npm install express
npm http GET http://registry.npmjs.org/express
npm http 304 http://registry.npmjs.org/express
npm http GET http://registry.npmjs.org/express/-/express-3.4.8.tgz
npm ERR! Error: getaddrinfo ENOENT
npm ERR! at errnoException (dns.js:31:11)
npm ERR! at Object.onanswer [as oncomplete] (dns.js:123:16)
npm ERR! { [Error: getaddrinfo ENOENT] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8a6b8a5e588afa7a7afa4adafbaa7bdb8bbe6aba7a5" rel="noreferrer noopener nofollow">[email protected]</a>>
最佳答案
就理解问题而言。问题在于您的计算机无法与以下设备建立连接:https://registry.npmjs.org/express/-/express-3.4.8.tgz
它正在尝试使用 HTTP GET 方法从 NPM 注册表的服务器检索文件,但似乎超时了:
npm http GET https://registry.npmjs.org/express/-/express-3.4.8.tgz
npm ERR! Error: tunneling socket could not be established, cause=connect ETIMEDOUT
这可能有几个原因,但我会提到两个主要原因:
- npmjs.org 的停机时间,可使用 http://status.npmjs.org/ 轻松检查
- 您的代理阻止了此操作
查看你的 npm 配置:
- 除非您有一个名为 proxy 的代理设置,否则这将不起作用。所以清除代理变量设置
- 使用
npm config set strict-ssl false
将严格 SSL 设置为 false - 如果这两个不起作用,请尝试使用
npm config setregistry http://registry.npmjs.org/将注册表设置为使用非加密连接
关于json - 使用 package.json 文件或不使用 package.json 文件安装 Express 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21879965/