无法在公司代理后面安装tfjs-node

时间:2020-07-08 03:34:36

标签: node.js tensorflow tfjs-node tensorflow.js

我制作了一个用于对象检测的tfjs解决方案,并希望将其部署在公司代理后面的服务器上。

发生问题是因为tensorflow\tfjs-node\scripts\install.js不支持代理,因此它试图直接从服务器获取https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.15.0.zip,而这是不可能的。'

我已经设置了我的npm配置

$npm config list

和console.log是:

; cli configs
metrics-registry = "http://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.4 node/v12.18.0 win32 x64"
; userconfig C:\Users\user\.npmrc
https-proxy = "http://182.192.254.44:8080/"
proxy = "http://182.192.254.44:8080/"
python = "="
registry = "http://registry.npmjs.org/"
strict-ssl = false
; builtin config undefined
prefix = "C:\\Users\\user\\AppData\\Roaming\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\IPA\beauty\TrackingServerProject
; HOME = C:\Users\usename
; "npm config ls -l" to show all defaults.

如您所见,由于代理服务器,我遇到下一个错误。

$ npm install @tensorflow/tfjs-node
> @tensorflow/tfjs-node@2.0.1 install C:\IPA\beauty\TrackingServerProject\node_modules\@te
> node scripts/install.js
CPU-windows-2.0.1.zip
* Downloading libtensorflow
events.js:292
      throw er; // Unhandled 'error' event
      ^
Error: connect ETIMEDOUT 64.233.189.128:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
npm ERR! @tensorflow/tfjs-node@2.0.1 install: `node scripts/install.js`

我认为我可能需要更改tensorflow\tfjs-node\scripts\install.js才能添加代理?

请帮助!

1 个答案:

答案 0 :(得分:0)

我成功地让它在3天的问题是代理定义后才能正常工作

tensorflow \ tfjs-node \ scripts \ resources.js(https://github.com/tensorflow/tfjs/blob/master/tfjs-node/scripts/resources.js

第40和41行

const proxy = process.env['HTTPS_PROXY'] || process.env['https_proxy'] ||
      process.env['HTTP_PROXY'] || process.env['http_proxy'] || '';

以方法1)或2)定义代理服务器时,不会检测到process.env

  1. npm config edit
  2. .npmrc

因此,您需要以以下形式传递PowerShell的系统变量: $env:HTTP_PROXY="http://182.192.254.44:8080/"

或对于CMD HTTP_PROXY=http://182.192.254.44:8080/

所以它将起作用

只需输入:npm install @tensorflow/tfjs-node即可享受!