Ramblings of a Tampa engineer

One day my build scripts started failing during the creation of assets.

Module build failed: ModuleBuildError: Module build failed: Error: Command failed: ~/node_modules/mozjpeg/vendor/cjpeg
~/node_modules/mozjpeg/vendor/cjpeg: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory

So I decided to go check that binary again, to check what shared dependencies it had.

[~/node_modules/mozjpeg/vendor]# ldd cjpeg 
	linux-vdso.so.1 =>  (0x00007ffd5cfab000)
	libpng16.so.16 => not found
	libm.so.6 => /lib64/libm.so.6 (0x00007f4f95c44000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f4f95877000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4f95f46000)

Usually, this is as easy as using yum to install libpng16. However, yum only had libpng12 and libpng15. Instead of installing some bulky repository, I decided to install this one manually.

wget https://download.sourceforge.net/libpng/libpng-1.6.34.tar.gz
md5sum libpng-1.6.34.tar.gz 

(ensure the md5 matches the package downloaded here)

Next up to configure & build it.

LIBS=-lpthread ./configure --prefix=/usr --disable-static && make
make install
ldconfig

Now we've built, installed and linked the dependency into our system. If the build failed, make sure you have the following build requirements.

yum install libtool automake autoconf nasm

Rerunning the same ldd command, we can print out the shared dependencies.

[~/node_modules/mozjpeg/vendor]# ldd cjpeg 
	linux-vdso.so.1 =>  (0x00007ffe4ca8f000)
	libpng16.so.16 => /lib/libpng16.so.16 (0x00007fb440792000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fb440490000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fb4400c3000)
	libz.so.1 => /lib64/libz.so.1 (0x00007fb43fead000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb43fc91000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fb4409c4000)

Now my asset deploys were back to working :)

DONE  Compiled successfully in 43567ms                                               

Featured image by Becca Tapert / Unsplash

You’ve successfully subscribed to Connor Tumbleson
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Success! Your email is updated.
Your link has expired
Success! Check your email for magic link to sign-in.