Node.js imagemin on CentOS
Asked Answered
S

5

6

I am trying to use Node.js imagemin to compress a lot of images on my server. I like using imagemin because I know how to point it at specific directories.

I am using CentOS 6 and when I run my file, I get the error:

node_modules/imagemin/node_modules/imagemin-pngquant/node_modules/pngquant-bin/vendor/pngquant: /lib64/libc.so.6: version `GLIBC_2.14' not found

Also, when I installed imagemin with npm install imagemin, I got an error that said:

Error: pngquant failed to build, make sure that libpng-dev is installed

Any ideas on what I can do to solve this?

Samuelsamuela answered 28/4, 2015 at 22:20 Comment(2)
It seems that you don't have libpng-dev installed. On CentOS, yum install libpng-dev should install it (not 100% sure about package name).Correlate
That did it. I was trying that earlier but I couldn't find the package initially so I thought it didn't exist on CentOS. It was named libpng-devel. Thank you.Samuelsamuela
C
11

(Problem de facto already solved in the comments - but for the sake of completion and future generations I'm posting an actual answer).

Error: pngquant failed to build, make sure that libpng-dev is installed

This error means that the system is lacking libpng development library, which is needed to install imagemin Node.JS module. To install it on CentOS 6, you need to issue this command:

yum install libpng-devel

Please note that both package manager (here - yum) and package name (libpng-devel) can vary between different Linux distributions.

Correlate answered 29/4, 2015 at 20:50 Comment(2)
Same problem appear with CentOS 7 with libpng-devel installed, version 1.5.13-7.Ethelinda
I have found a solution afterwards and I have shared it as a separate answer. Thanks!Ethelinda
E
9

I had the same issue with CentOS 7 even with libpng-devel installed. It seems the package carries a precompiled binary program in node_modules/pngquant-bin/vendor/pngquant which is somehow incompatible with the Linux installation (CentOS 7 latest).

I have made a solution to the problem by replacing this binary file with the one that is available for CentOS 7.

I am installing the official package pngquant with yum, first. Then I am installing the node modules. You can remove the node_modules folder if you like prior to install action. Its not required, though.

The error will be shown as usual (the program file is not yet replaced):

⚠ The `node_modules/pngquant-bin/vendor/pngquant` binary doesn't seem to work correctly ⚠ pngquant pre-build test failed ℹ compiling from source ✖ Error: pngquant failed to build, make sure that libpng-dev is installed at ChildProcess.exithandler (child_process.js:206:12) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:877:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

However, after replacing the binary file everything should be fine.

sh yum install libpng-devel pngquant npm install rm -rf node_modules/pngquant-bin/vendor/pngquant ln -s /usr/bin/pngquant node_modules/pngquant-bin/vendor/pngquant

After that you can run any command you like, "imagemin:dynamic", etc. It should work properly.

Summary

Generally speaking, the problem appear to be inside the pngquant-bin node package. This solution might help for other Linux distributions as well.

The solution itself is to install the officially supported version of pngquant with the OS package manager and to replace the binary inside the pngquant-bin vendor folder after its installation.

Update

In addition, there is a recent problem that is still related with pngquant npm package. It seems that there is a buggy release of it - lock the required pngquant package in your package.json to older version (last properly running version for you).

Ethelinda answered 8/8, 2017 at 11:36 Comment(0)
G
6

The previous solutions didn't work for me. I'm using centos 7.4

When executing executing

# npm install

I recieved the error:

✖ Error: pngquant failed to build, make sure that libpng-dev is installed`

While trying to install libpng-devel, it says it's already installed.

Solution

Update the nodejs & npm version if it's using old one.

I have updated to

Nodejs Version

[root@hosting ~]# node -v

v8.10.0

npm version

[root@hosting ~]# npm -v

5.7.1

Check the installed libpng-devel on your server.

[root@hosting ~]# rpm -qa |grep libpng

libpng-1.5.13-7.el7_2.x86_64

libpng-devel-1.5.13-7.el7_2.x86_64

If you are using epel repo then it will install the latest version. For more libpng release check

[root@hosting ~]# yum list |grep libpng

I have installed

yum install libpng12-1.2.50-10.el7.x86_64 libpng12-devel-1.2.50-10.el7.x86_64

moved node modules

mv node_modules node_modules_bak

Then type

# npm install
Gilbertine answered 22/3, 2018 at 11:28 Comment(0)
S
1

in my case, I'm using a CentOS instance on Amazon WS and I faced same problem here. I solved it by installing libpng12 and libpng12-devel (yum install libpng12 libpng12-devel), then running yarn install (or npm install) and the packages did installed correctly.

Just this!

Stifle answered 21/5, 2019 at 13:44 Comment(1)
AWS CodeBuild - it worked! This answer should have more points.Autobiographical
M
0

Here's how I resolved the issue for my case:

Delete node_modules:

rm -rf node_modules

Install following dependencies:

sudo dnf install libpng-devel pngquant gcc make libpng12 libpng12-devel

Rebuild dependencies. I use yarn:

yarn
Marasco answered 8/10, 2018 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.