javascript CentOS 上的 Node.js imagemin
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29930978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js imagemin on CentOS
提问by Sean
I am trying to use Node.js imageminto compress a lot of images on my server. I like using imageminbecause I know how to point it at specific directories.
我正在尝试使用Node.js imagemin来压缩我服务器上的大量图像。我喜欢使用imagemin,因为我知道如何将它指向特定目录。
I am using CentOS 6 and when I run my file, I get the error:
我正在使用 CentOS 6,当我运行我的文件时,出现错误:
node_modules/imagemin/node_modules/imagemin-pngquant/node_modules/pngquant-bin/vendor/pngquant: /lib64/libc.so.6: version `GLIBC_2.14' not found
node_modules/imagemin/node_modules/imagemin-pngquant/node_modules/pngquant-bin/vendor/pngquant:/lib64/libc.so.6:未找到版本“GLIBC_2.14”
Also, when I installed imageminwith npm install imagemin, I got an error that said:
另外,当我用 安装imagemin时npm install imagemin,我收到一个错误消息:
Error: pngquant failed to build, make sure that libpng-dev is installed
错误:pngquant 构建失败,请确保安装了 libpng-dev
Any ideas on what I can do to solve this?
关于我可以做些什么来解决这个问题的任何想法?
回答by bardzusny
(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
错误:pngquant 构建失败,请确保安装了 libpng-dev
This error means that the system is lacking libpngdevelopment library, which is needed to install imageminNode.JS module. To install it on CentOS 6, you need to issue this command:
此错误表示系统缺少libpng安装imageminNode.JS 模块所需的开发库。要在 CentOS 6 上安装它,您需要发出以下命令:
yum install libpng-devel
yum install libpng-devel
Please note that both package manager (here - yum) and package name (libpng-devel) can vary between different Linux distributions.
请注意,包管理器(此处为 - yum)和包名称 ( libpng-devel) 在不同的 Linux 发行版之间可能会有所不同。
回答by Rolice
I had the same issue with CentOS 7 even with libpng-develinstalled. It seems the package carries a precompiled binary program in node_modules/pngquant-bin/vendor/pngquantwhich is somehow incompatible with the Linux installation (CentOS 7 latest).
即使libpng-devel安装了 CentOS 7,我也遇到了同样的问题。该软件包似乎带有一个预编译的二进制程序,node_modules/pngquant-bin/vendor/pngquant其中与 Linux 安装(最新的 CentOS 7)不兼容。
I have made a solution to the problem by replacing this binary file with the one that is available for CentOS 7.
我通过用 CentOS 7 可用的二进制文件替换这个二进制文件来解决这个问题。
I am installing the official package pngquantwith yum, first. Then I am installing the node modules. You can remove the node_modulesfolder if you like prior to install action. Its not required, though.
我安装了官方包pngquant带yum,第一。然后我正在安装节点模块。node_modules如果您愿意,可以在安装操作之前删除该文件夹。不过,这不是必需的。
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)
? 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
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.
之后你可以运行任何你喜欢的命令,“imagemin:dynamic”等。它应该可以正常工作。
Summary
概括
Generally speaking, the problem appear to be inside the pngquant-binnode package. This solution might help for other Linux distributions as well.
一般来说,问题出现在pngquant-bin节点包内部。此解决方案也可能对其他 Linux 发行版有所帮助。
The solution itself is to install the officially supported versionof pngquantwith the OS package manager and to replace the binary inside the pngquant-binvendor folder after its installation.
解决方案本身是使用操作系统包管理器安装官方支持的版本,pngquant并在pngquant-bin安装后替换供应商文件夹中的二进制文件。
Update
更新
In addition, there is a recent problem that is still related with pngquantnpm package. It seems that there is a buggy release of it - lock the required pngquantpackage in your package.jsonto older version (last properly running version for you).
另外,最近还有一个问题,还是和pngquantnpm包有关。它似乎有一个错误的版本 - 将所需的pngquant包锁定package.json到旧版本(最后为您正确运行的版本)。
回答by uday
The previous solutions didn't work for me. I'm using centos 7.4
以前的解决方案对我不起作用。我正在使用 centos 7.4
When executing executing
执行执行时
# npm install
I recieved the error:
我收到错误:
? Error: pngquant failed to build, make sure that libpng-dev is installed`
? 错误:pngquant 无法构建,请确保已安装 libpng-dev`
While trying to install libpng-devel, it says it's already installed.
在尝试安装时libpng-devel,它说它已经安装了。
Solution
解决方案
Update the nodejs & npm version if it's using old one.
如果使用旧版本,请更新 nodejs 和 npm 版本。
I have updated to
我已经更新到
Nodejs Version
节点版本
[root@hosting ~]# node -v
v8.10.0
v8.10.0
npm version
npm 版本
[root@hosting ~]# npm -v
5.7.1
5.7.1
Check the installed libpng-devel on your server.
检查服务器上已安装的 libpng-devel。
[root@hosting ~]# rpm -qa |grep libpng
libpng-1.5.13-7.el7_2.x86_64
libpng-1.5.13-7.el7_2.x86_64
libpng-devel-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
如果您使用的是 epel repo,那么它将安装最新版本。有关更多 libpng 发布检查
[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
回答by Divyanshu Maithani
Here's how I resolved the issue for my case:
以下是我如何解决我的案例问题:
Delete node_modules:
删除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:
yarn
回答by Christiano Marques
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.
就我而言,我在 Amazon WS 上使用 CentOS 实例,但在这里遇到了同样的问题。我通过安装 libpng12 和 libpng12-devel(yum install libpng12 libpng12-devel)解决了这个问题,然后运行 yarn install(或 npm install)并且软件包安装正确。
Just this!
只是这个!

