javascript - 如何解决代理后面的 npm install 期间的连接问题?

标签 javascript node.js npm proxy electron

我按照指示:
https://www.electronjs.org/docs/tutorial/first-app

我输入了 mkdir , cdnpm init .他们都运作良好。一个名为 package.json 的文件出现了。

然后我输入 npm install --save-dev electron .发生了一些错误。

lala@ubu:~/projects/electron/my-app 17:20:34
$ npm install --save-dev electron

> core-js@3.6.4 postinstall /home/lala/projects/electron/my-app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> electron@8.0.0 postinstall /home/lala/projects/electron/my-app/node_modules/electron
> node install.js

(node:5950) UnhandledPromiseRejectionWarning: RequestError: connect ETIMEDOUT 13.250.177.223:443
    at ClientRequest.<anonymous> (/home/lala/projects/electron/my-app/node_modules/got/source/request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:313:26)
    at ClientRequest.emit (events.js:228:7)
    at ClientRequest.origin.emit (/home/lala/projects/electron/my-app/node_modules/@szmarczak/http-timer/source/index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:406:9)
    at TLSSocket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
(node:5950) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5950) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN my-app@1.0.0 No description
npm WARN my-app@1.0.0 No repository field.

+ electron@8.0.0
added 85 packages from 91 contributors and audited 102 packages in 87.419s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

执行上述指令后,一个文件夹node_modules和一个文件package-lock.json出现了。

看来我已经成功安装了依赖项。但是为什么会出现一个连接错误?

我无法访问 github.com(13.250.177.223)直接,但我的代理工作。

我已将代理配置如下,但连接错误仍然存​​在。

我的 ~/.bashrc
export HTTP_PROXY=http://127.0.0.1:8123/
export HTTPS_PROXY=http://127.0.0.1:8123/
export http_proxy=http://127.0.0.1:8123/
export https_proxy=http://127.0.0.1:8123/
$ cat ~/.npmrc 
proxy=http://127.0.0.1:8123/
http-proxy=http://127.0.0.1:8123/
https-proxy=http://127.0.0.1:8123/
noproxy=localhost,127.0.0.1,192.168.,10.
strict-ssl=false

Node v12.14.1 npm v6.13.7

我怎样才能减少错误?

谢谢你的帮助!

最佳答案

试试这个从代理后面安装 Electron Node 模块的解决方案。

npx cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://username:password@host:8080 npm install -D electron@latest
  • 这里 username:password是您的网络用户名和密码(如果需要)。
  • 这里 host:8080是您的代理服务器主机名和端口号。
  • cross-env是另一个支持命令行变量的 Node 模块(可选)。
  • 关于javascript - 如何解决代理后面的 npm install 期间的连接问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60054531/

    相关文章:

    javascript - 在每个 ng-repeat 之后添加元素

    javascript - 模糊 DOM 元素时会发生什么

    javascript - 如何为我所有的 Express 中间件设置默认的拒绝 promise 行为?

    mysql - 关于 mysql 数据库的 NodeJS 连接 ECONNREFUSED 错误

    json - NPM 安装失败并出现神秘的 "Unexpected token in JSON"错误

    Javascript:全局变量=坏?

    javascript - 从 ember.js 中的 set 函数获取无限循环

    javascript - 如何在 for 循环中使用 node.js 中的 Request 函数并让它以正确的顺序返回输出?

    angularjs - Angular 2 问题 : typings: command not found

    javascript - 如何使用 npm start 和 expo start 运行 React Native expo