The libpng16 mozjpeg help guide.

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: 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 =>  (0x00007ffd5cfab000) => not found => /lib64/ (0x00007f4f95c44000) => /lib64/ (0x00007f4f95877000)
	/lib64/ (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.

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

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 =>  (0x00007ffe4ca8f000) => /lib/ (0x00007fb440792000) => /lib64/ (0x00007fb440490000) => /lib64/ (0x00007fb4400c3000) => /lib64/ (0x00007fb43fead000) => /lib64/ (0x00007fb43fc91000)
	/lib64/ (0x00007fb4409c4000)

Now my asset deploys were back to working :)

DONE  Compiled successfully in 43567ms                                               

Featured image by Becca Tapert / Unsplash