我是Stackoverflow的新手,所以大家好!
我也是OpenShift Online(免费的入门帐户)上的部署新手。部署需要NPM打包的Sharp(https://www.npmjs.com/package/sharp)的个人NodeJS应用时,我遇到以下错误。
该应用是直接从本地Git存储库中进行的“二进制构建”(https://docs.openshift.com/container-platform/3.6/dev_guide/dev_tutorials/binary_builds.html)。开始构建时,我得到以下输出(初始的相关行):
Receiving source from STDIN as archive ...
Pulling image "docker-registry.default.svc:5000/openshift/nodejs@sha256:0486de81685b610e47314d8b100c4cfae65edb3294d02f0a29ea57408e171fb6" ...
---> Installing application source ...
---> Installing all dependencies
> sharp@0.20.5 install /opt/app-root/src/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.6.1/libvips-8.6.1-linux-x64.tar.gz
prebuild-install WARN install /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /opt/app-root/src/node_modules/sharp/build/Release/../../vendor/lib/libpng16.so.16)
...
构建完成并自动触发新的部署,但是启动失败,当然:
Environment:
DEV_MODE=false
NODE_ENV=production
DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using npm@5.6.0
npm info using node@v8.9.4
...
> node app.js
module.js:672
return process.dlopen(module, path._makeLong(filename));
^
Error: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /opt/app-root/src/node_modules/sharp/build/Release/../../vendor/lib/libpng16.so.16)
at Object.Module._extensions..node (module.js:672:18)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/app-root/src/node_modules/sharp/lib/constructor.js:10:15)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/app-root/src/node_modules/sharp/lib/index.js:3:15)
at Module._compile (module.js:643:30)
在电子(https://github.com/lovell/sharp/issues/892)的上下文中,或者当还使用节点画布时(我不这样做; https://github.com/lovell/sharp/issues/843),我发现了一些有关此错误的讨论。由于我也不熟悉Dockers等,因此很难提取与我的案例相关的信息。
在我的本地计算机上(Ubuntu 16.04)可以很好地安装该锋利的软件包,因此该应用程序可以正常运行。我还尝试在主app.js文件中明确要求Sharp作为第一行,这没有帮助。
感谢所有帮助,谢谢!
编辑7月2日:在上述与电子有关的讨论中,我想到了设置环境变量的想法
LD_PRELOAD="/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so"
在OpenShift上的NodeJS-app的构建环境中。构建日志更改如下:
Receiving source from STDIN as archive ...
Pulling image "docker-registry.default.svc:5000/openshift/nodejs@sha256:0486de81685b610e47314d8b100c4cfae65edb3294d02f0a29ea57408e171fb6" ...
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
---> Installing application source ...
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
---> Installing all dependencies
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
> sharp@0.20.5 install /opt/app-root/src/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' from LD_PRELOAD cannot be preloaded: ignored.
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.6.1/libvips-8.6.1-linux-x64.tar.gz
added 170 packages in 19.982s
构建过程中的警告已消失,但该应用程序仍无法以与之前完全相同的错误启动。 (是的,我确实在主app.js中首先加载了Sharp。)
我不能以某种方式直接告诉NodeJS(在主app.js中)为某些路径(或库)提供优先级吗?
答案 0 :(得分:0)
到现在我已经解决了这个问题。将LD_PRELOAD变量添加到内部版本和部署环境并没有帮助。但是,一旦我修改了npm start脚本以在启动应用程序之前添加变量,它就会起作用:
"start": "LD_PRELOAD='/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so' node app.js"
在我的主要app.js文件中,我仍然首先需要Sharp。没有测试这是否真的必要。