我正试着在代理后面跑npm英里.我try 过直接或通过Authoxy输入代理:

npm config set proxy http://localhost:8999
npm config set https-proxy http://localhost:8999

无论我使用哪个代理,在运行npm search时,我总是会出现相同的错误:

npm info it worked if it ends with ok
npm verb cli [ 'node', '/usr/local/bin/npm', 'search' ]
npm info using npm@1.1.45
npm info using node@v0.8.4
npm verb config file /Users/xxx/.npmrc
npm verb config file /usr/local/etc/npmrc
npm verb config file /usr/local/lib/node_modules/npm/npmrc
npm WARN Building the local index for the first time, please be patient
npm verb url raw /-/all
npm verb url resolving [ 'https://registry.npmjs.org/', './-/all' ]
npm verb url resolved https://registry.npmjs.org/-/all
npm info retry registry request attempt 1 at 09:48:47
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 2 at 09:48:57
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 3 at 09:49:57
npm http GET https://registry.npmjs.org/-/all
npm ERR! Error: tunneling socket could not be established, sutatusCode=403
npm ERR!     at ClientRequest.onConnect (/usr/local/lib/node_modules/npm/node_modules/request/tunnel.js:148:19)
npm ERR!     at ClientRequest.g (events.js:185:14)
npm ERR!     at ClientRequest.EventEmitter.emit (events.js:115:20)
npm ERR!     at Socket.socketOnData (http.js:1383:11)
npm ERR!     at TCP.onread (net.js:410:27)

命令总是以sutatusCode[sic!]403-这意味着未经授权.我已将Authoxy设置为不需要用户名/密码.当我绕过Authoxy并以http://user:pass@proxy:左舷.

我如何通过代理来实现这一点?

Update

我在NPM项目上创建了一个问题来报告这一点:https://github.com/isaacs/npm/issues/2866

推荐答案

好的,在发帖几分钟后,我在这里找到了答案:

问题似乎是,npm在代理上使用HTTPS时并没有那么好.将注册表URL从HTTPS更改为HTTP为我修复了它:

npm config set registry http://registry.npmjs.org/

我仍然需要提供代理配置(在我的例子中是通过Authoxy),但现在一切都正常了.

这似乎是一个常见的问题,但没有很好的记录.我希望这个答案能让人们在遇到这个问题时更容易找到答案.

Node.js相关问答推荐

意外标识符断言Shopify Remix应用程序

CloudTasksClient在Firebase Function % s onDocumentCreated中实例化时导致错误

使用AWS SDK for JavaScript V3将图像从node.js上传到s3 bucket

使用NodeJS通过服务账号列出Google Workspace用户

运行本地移动自动化测试时,在onPrepare钩子中,ERROR @wdio/cli:utils: A service failed in the 'onPrepare'

Amplify 部署的应用程序出现TypeError: handler is not a function错误,但它在本地运行

Gulp 能否向 Docker 发出增量构建的第一次迭代完成的信号?

具有项目外部子路径导入的 Firebase 函数

为什么 nginx 不将我的 react index.html 作为后备服务

ResponseError:键空间ks1不存在

nvm / node / npm: node 12 的 npm 比 node 14 的更新?

来自 child_process.exec 的错误没有这样的设备或地址,管道有帮助.为什么?

无法通过谷歌Electron 表格 api( node js)中的服务帐户访问写入

自定义 Docker 容器 Github 操作无法在 /github/workspace 中找到 Node 脚本

搜索MongoDB条目的正确方法是'_id';在 node 中

我可以向NPM添加调试脚本吗?

运行摩卡+伊斯坦布尔+通天塔

我可以在 Heroku 中运行咖啡脚本吗?

如何解决'npm应该在 node repl之外运行,在你的普通shell中'

Node.js `--nolazy` 标志是什么意思?