部署到 IBM Cloud 时出现问题

Problems deploying to IBM Cloud

我在 NodeJS 中创建了一个 Web 应用程序,它使用 Tensorflow 从 Python 中训练的模型中获取预测。我想要做的是通过 IBM Cloud 的 Cloud Foundry SDK for NodeJS 进行部署。我 运行 遇到的问题是当我试图将我的项目推送到 IBM Cloud 时。通过查看控制台中的日志,似乎 TensorflowJS Node 在安装和运行时

node-gyp rebuild

它会导致一些问题。出于某种原因,它在 运行 是

时遇到错误

/temp/app/node_modules/@tensorflow/tfjs-node/deps/tensorflow/lib/libtensorflow.so: file not recognized: File format not recognized

并由此导致一长串错误。有人知道我该如何解决这个问题吗?

这是命令行日志。

Downloaded build artifacts cache (484.1K)
Staging...
-----> IBM SDK for Node.js Buildpack v3.21-20180628-1258
      Based on Cloud Foundry Node.js Buildpack v1.5.24
-----> Creating runtime environment

      NPM_CONFIG_LOGLEVEL=error
      NPM_CONFIG_PRODUCTION=true
      NODE_ENV=production
      NODE_MODULES_CACHE=true
-----> Installing binaries
      engines.node (package.json):  unspecified
      engines.npm (package.json):   unspecified (use default)

      Resolving node version (latest stable) via 'node-version-resolver'
      Installing IBM SDK for Node.js (6.14.3) from cache
      Using default npm version: 3.10.10
-----> Restoring cache
      Loading 2 from cacheDirectories (default):
      - node_modules (exists - skipping)
      - bower_components (not cached - skipping)
-----> Checking and configuring service extensions before installing 
dependencies
-----> Building dependencies
      Prebuild detected (node_modules already exists)
      Rebuilding any native modules

      > protobufjs@6.8.8 postinstall /tmp/app/node_modules/protobufjs
      > node scripts/postinstall


      > @tensorflow/tfjs-node@0.1.9 install 
/tmp/app/node_modules/@tensorflow/tfjs-node
      > node-gyp rebuild

      make: Entering directory `/tmp/app/node_modules/@tensorflow/tfjs- 
node/build'
      ACTION binding_gyp_tfjs_binding_target_download_libtensorflow 
Release/libtensorflow.so
      CXX(target) Release/obj.target/tfjs_binding/binding/tfe_utils.o
      CXX(target) Release/obj.target/tfjs_binding/binding/tfjs_backend.o
      CXX(target) Release/obj.target/tfjs_binding/binding/tfjs_binding.o
      SOLINK_MODULE(target) Release/obj.target/tfjs_binding.node
      /tmp/app/node_modules/@tensorflow/tfjs- 
node/deps/tensorflow/lib/libtensorflow.so: file not recognized: File 
format 
not recognized
      collect2: error: ld returned 1 exit status
      make: *** [Release/obj.target/tfjs_binding.node] Error 1
      make: Leaving directory `/tmp/app/node_modules/@tensorflow/tfjs- 
node/build'
      gyp ERR! build error
      gyp ERR! stack Error: `make` failed with exit code: 2
      gyp ERR! stack     at ChildProcess.onExit 
(/tmp/app/vendor/node/lib/node_modules/npm/node_modules/node- 
gyp/lib/build.js:276:23)
      gyp ERR! stack     at emitTwo (events.js:106:13)
      gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
      gyp ERR! stack     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:219:12)
      gyp ERR! System Linux 4.4.0-109-generic
      gyp ERR! command "/tmp/app/vendor/node/bin/node" 
"/tmp/app/vendor/node/lib/node_modules/npm/node_modules/node- 
gyp/bin/node- gyp.js" "rebuild"
      gyp ERR! cwd /tmp/app/node_modules/@tensorflow/tfjs-node
      gyp ERR! node -v v6.14.3
      gyp ERR! node-gyp -v v3.4.0
      gyp ERR! not ok

      npm ERR! code ELIFECYCLE
      npm ERR!
      npm ERR! Failed at the @tensorflow/tfjs-node@0.1.9 install script 
'node-gyp rebuild'.
      npm ERR! Make sure you have the latest version of node.js and npm 
installed.
      npm ERR!     node-gyp rebuild
      npm ERR! Linux 4.4.0-109-generic
      npm ERR! argv "/tmp/app/vendor/node/bin/node" 
"/tmp/app/vendor/node/bin/npm" "rebuild" "-- 
nodedir=/tmp/app/vendor/node"
      npm ERR! node v6.14.3
      npm ERR! npm  v3.10.10
      npm ERR! @tensorflow/tfjs-node@0.1.9 install: `node-gyp rebuild`
      npm ERR! Exit status 1
      npm ERR! If you do, this is most likely a problem with the 
@tensorflow/tfjs-node package,
      npm ERR! not with npm itself.
      npm ERR! Tell the author that this fails on your system:
      npm ERR! You can get information on how to open an issue for this 
project with:
      npm ERR!     npm bugs @tensorflow/tfjs-node
      npm ERR! Or if that isn't available, you can get their info via:
      npm ERR!     npm owner ls @tensorflow/tfjs-node
      npm ERR! There is likely additional logging output above.

      npm ERR! Please include the following file with any support 
request:
      npm ERR!     /tmp/app/npm-debug.log
-----> Build failed

      Some possible problems:

      - node_modules checked into source control
      http://docs.cloudfoundry.org/buildpacks/node/node-tips.html

      - Node version not specified in package.json
      http://docs.cloudfoundry.org/buildpacks/node/node-tips.html

Failed to compile droplet: Failed to compile droplet: exit status 1
Exit status 223
Staging failed: STG: Exited with status 223
Stopping instance 4e1dd2ee-71b4-4f84-95e8-c5f6c7bd24e0
Destroying container
Error staging application: App staging failed in the buildpack compile 
phase
FAILED

您的云环境安装的NodeJs版本问题。错误显示正在使用的 NodeJs 版本是 Node.js (6.14.3) 而 tensorflowJs 需要 Node V8+

出于某种原因,如果我从工作目录中删除 node_modules 文件夹,然后尝试推送到 IBM Cloud,它就可以正常工作。我的猜测可能是因为当 Tensorflow 安装时它会根据您的操作系统安装某些文件,在我的情况下

libtensorflow.so

是这些文件之一。