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

一、问题描述:

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

path D:\workspace\study\\xxx\node_modules\pngquant-bin
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node lib/install.js
npm ERR! ‼ getaddrinfo ENOENT raw.githubusercontent.com
npm ERR!   ‼ pngquant pre-build test failed
npm ERR!   i compiling from source
npm ERR!   √ pngquant pre-build test passed successfully
npm ERR!   × Error: pngquant failed to build, make sure that libpng-dev is installed
npm ERR!     at D:\workspace\study\xxx\node_modules\pngquant-bin\node_modules\bin-build\node_modules\execa\index.js:231:11
npm ERR!     at runMicrotasks (``)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR!     at async Promise.all (index 0)

二、解决方案:

For Windows OS users:

  • When you install pngquant-bin through npm. (e.g: npm install [email protected]), The post-install step defined in package.json will try to download the pre-built binary from https://raw.githubusercontent.com/imagemin/pngquant-bin/v6.0.0/vendor/win/pngquant.exe. And test running it with pngquant.exe --version to check if the return code is zero. If it failed to get zero return, the ‘build from source’ phase would be triggered.
  • For most users, using the pre-built binary is the expected way. But there are 2 common problems that would lead you into ‘building from source’ phase:
    1. Failed to resolve the domain name raw.githubusercontent.com which is commonly caused by DNS pollution.
    2. Lack of corresponding Visual C++ runtime library that pngquant.exe depends on. (For example, [email protected] relies on VCRUNTIME140.dll.) If you don’t have the proper VC runtime library installed on your Windows OS, the post-install process would be failed in test running the downloaded binary, but it will directly catch the error and you won’t see any error message box pop-up. The post-install logic then turns to build from source in the error-catch procedure.
  • To solve the problems:
    1. Add the correct IP for raw.githubusercontent.com in the dnsmasq config file on your router or local HOST file in your Windows OS.
    2. Download and install all latest VC runtime library here: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Thank you, It is useful on my win os! Just two simple steps here:

  1. Edit local dns host file and append raw.githubusercontent.com ip-domain pair;
  2. download 2015-2022 vc and install it;
    Then it is worked! Awesome!

访问 https://www.ipaddress.com/ ,在页面输入刚刚找到的域名:raw.githubusercontent.com

可以得到IP地址如下:
Error: pngquant failed to build, make sure that libpng-dev is installed_第1张图片

找到本机hosts文件,一般路径地址为:C:\Windows\System32\drivers\etc\hosts

打开hosts修改,将上面对应的IP和域名放到hosts文件末尾

即添加:

185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
2606:50c0:8000::154 raw.githubusercontent.com
2606:50c0:8001::154 raw.githubusercontent.com
2606:50c0:8002::154 raw.githubusercontent.com
2606:50c0:8003::154 raw.githubusercontent.com

ps: 添加完此映射关系之后,可以使用这个命令刷新下本地的DNS缓存:ipconfig/flush,打开CMD,输入 ipconfig/flushdns 即可。

你可能感兴趣的:(开发问题,#,Node开发问题,javascript,前端,npm)