I'm new to Stackoverflow, so "hi" to everyone!
I'm also new to deployment on OpenShift Online (free starter account). I run into the following error when deploying a personal NodeJS app requiring NPM-package sharp (https://www.npmjs.com/package/sharp).
The app is a "binary build" (https://docs.openshift.com/container-platform/3.6/dev_guide/dev_tutorials/binary_builds.html) directly from a local Git repo. When starting the build, I get the following output (initial, relevant lines):
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)
...
The build finishes and auto-triggers a new deployment, which fails starting, of course:
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)
I found several discussions on this error in the context of Electron (https://github.com/lovell/sharp/issues/892) or when node-canvas is also used (which I don't; https://github.com/lovell/sharp/issues/843). It's hard for me to extract the information relevant for my case, since I'm also not familiar with Dockers etc.
The sharp package installed fine on my local machine (Ubuntu 16.04), and consequently, the app runs fine. I also tried explicitly requiring sharp as very first line in my main app.js file, which did not help.
Every help is appreciated, thanks!
Edit July 2: From the above-mentioned Electron-related discussion, I took the idea to set the env-variable
LD_PRELOAD="/opt/app-root/src/node_modules/sharp/vendor/lib/libz.so"
in the build-environment for the NodeJS-app on OpenShift. The build log changed as follows:
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
The warning during the build is gone, but the app still does not startup with exactly the same error than before. (And yes, I do load sharp as first thing in the main app.js.)
Can't I somehow directly tell NodeJS (in the main app.js) to give preference to some path (or library)?
By now I solved the problem. Adding the LD_PRELOAD variable to the build and the deployment environments did not help. However, it worked once I modified the npm start script to add the variable before starting the app:
I am still requiring sharp as first thing in my main app.js file; did not test whether this is actually necessary.