简体   繁体   English

npm安装抛出错误错误:协议无效

[英]npm install throwing errors Error: Invalid protocol

Hi I am new to Node JS and i am trying to follow the sample in the book and when trying to do npm install i get the following error: 嗨,我是Node JS的新手,我正在尝试按照本书中的示例进行操作,当我尝试执行npm install时,我收到以下错误:

Any help will be highly appreciated 任何帮助将受到高度赞赏

 C:\Developer\NODE_JS>npm install
    npm WARN package.json chatrooms@0.0.1 No repository field.
    npm WARN package.json chatrooms@0.0.1 No README data
    npm http GET http://registry.npmjs.org/socket.io
    npm http GET http://registry.npmjs.org/mime
    npm http GET http://registry.npmjs.org/socket.io
    npm http GET http://registry.npmjs.org/mime
    npm http GET http://registry.npmjs.org/socket.io
    npm http GET http://registry.npmjs.org/mime
    npm ERR! Error: Invalid protocol
    npm ERR!     at Request.init (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:335:51)
    npm ERR!     at new Request (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:99:8)
    npm ERR!     at request (C:\Program Files\nodejs\node_modules\npm\node_modules\request\index.js:55:11)
    npm ERR!     at RegClient.makeRequest (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\request.js:211:13)
    npm ERR!     at RegClient.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\request.js:117:17)
    npm ERR!     at null._onTimeout (C:\Program Files\nodejs\node_modules\npm\node_modules\retry\lib\retry_operation.js:32:10)
    npm ERR!     at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
    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/isaacs/npm/issues>

    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 C:\Developer\NODE_JS
    npm ERR! node -v v0.10.24
    npm ERR! npm -v 1.3.21
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR!     C:\Developer\NODE_JS\npm-debug.log
    npm ERR! not ok code 0

My Node js config is 我的节点js配置是

C:\Developer\NODE_JS>npm config list
; cli configs
registry = "http://registry.npmjs.org/"

; userconfig C:\Users\<uname>\.npmrc
https-proxy = "proxy.<comp>.com:8080"
proxy = "proxy.<comp>.com:8080"
registry = "http://registry.npmjs.org/"

; builtin config undefined
prefix = "C:\\Users\\puppalap\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\\node.exe
; cwd = C:\Developer\NODE_JS
; HOME = C:\Users\<uname>
; 'npm config ls -l' to show all defaults.

The issue got resolved after i set the following two properties: 设置以下两个属性后问题得到解决:

npm config set proxy http://usr:pwd@host:port
npm config set https-proxy http://usr:pwd@host:port

Issue is due to windows http_proxy environment variable being set; 问题是由于windows http_proxy环境变量被设置; while I don't use a proxy. 虽然我不使用代理。

Following command in command prompt will display, if http_proxy is set; 如果设置了http_proxy,将显示命令提示符中的以下命令;

set http

If set removed the variable with below command and problem solved. 如果设置已删除变量,则使用以下命令解决问题。

set http_proxy=

Above command will remove the http_proxy from the current command line. 上面的命令将从当前命令行中删除http_proxy。 However, if you need to permanently remove it, just remove it from System Properties>Advanced Tab>Environment Variables dialog box. 但是,如果需要永久删除它,只需将其从“系统属性”>“高级”选项卡>“环境变量”对话框中删除即可。

Just want to share a method,the way i followed to get it resolved, 只是想分享一个方法,我按照我的方式来解决它,

My error: was ERR! 我的错误:是ERR! Error: Invalid protocol : myusername: 错误:协议无效:myusername:

[username of the previous proxy] [前一个代理的用户名]

where my .npmrc file contains registry="http://registry.npmjs.org/" and other variables[prefix,cwd,home] 我的.npmrc文件包含registry =“http://registry.npmjs.org/”和其他变量[prefix,cwd,home]

As i am not behind the proxy, removed proxy variables still got the same error 由于我不在代理后面,删除代理变量仍然得到相同的错误

when looked into request.js[/usr/lib/node_modules/npm/node_modules/request/request.js] file it is using the old proxy values 当查看request.js [/usr/lib/node_modules/npm/node_modules/request/request.js]文件时,它正在使用旧的代理值

Hence , i added the line in init() of request.js 因此,我在request.js的init()中添加了这一行

self.proxy="http://registry.npmjs.org/" //at the start of method

then it started working!!! 然后它开始工作了!

PS: Once after install command,Removed this line and it continued to work. PS:安装命令后,删除此行并继续工作。 Try this , if no other options are working 如果没有其他选项可用,请尝试此操作

If you're on a Linux box make sure you set the following variables: 如果您在Linux机器上,请确保设置以下变量:

export http_proxy="http://yourCompanyProxy:portNumber"
export https_proxy="http://yourCompanyProxy:portNumber"
export HTTP_PROXY="http://yourCompanyProxy:portNumber"
export HTTPS_PROXY="http://yourCompanyProxy:portNumber"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM