gatsby: `yarn add xxxx` error "pngquant pre-build test failed"
os: MacOS 10.15.2
- Every time I install the package, I get the error
pngquant pre-build test failed, macOS cannot install “libpng-dev”, only “libpng”
每次安装包裹,都会出现
pngquant pre-build test failed这个错误,macOS 无法安装 “libpng-dev”, 只有“libpng”
Is there a stable solution? 有稳定的解决方案吗?
- The result of my attempt
我尝试的结果
brew install libpng Install once, reopen iterm Use sudo yarn add xxx to complete the installation, but the above problems will still occur next time, you can only install libpng repeatedly! It ’s bad!
brew install libpng 安装一次,重新打开 iterm 使用 sudo yarn add xxx 可以完成安装,但是下次安装还是会出现以上问题,只能反复的安装 libpng 很糟糕!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (3 by maintainers)
I meet the same problem. But I have been yarn it successful. I will be sharing my experience below. I install libpng on my mac. then yarn, It still errors. So I view https://pngquant.org/install.html and try to install pngquant. But it makes errors.
So I
brew install pkg-config, then I yarn, it works! Actually, It makes errors, Because some dependencies missed.中文
The following content is generated by Google Translate, if there are any errors, please let me know
Reason:
The reason is that the default site generated by Gatsby depends on a package
pngquant-binpngquant-binwill go toraw.githubusercontent.comto download the corresponding binary file according to different platforms.When the download fails, it will start to compile and generate the binary file from the source code.raw.githubusercontent.comis blocked in China, When we don’t have an environment that can compilepngquant-bin, the installation fails.Usually we can configureHTTP_PROXYto allow terminal programs to access the blocked network through a proxy.pngquant-binis used to download the dependent package isbin-wrapper -> download -> got. Finally, the file is downloaded viagotHowever,gotdoes not support the use of environment variables to set the proxy. For example, we often use the value of HTTP_PROXY to set the proxy, which has no effect ongot.gotcan only set the agent manually when using the package, or use theglobal-agentmethod to deal with it. Unfortunately, when installingpngquant-bin, I have not found a place where these two methods can be used. If anyone knows, can tell me.Solution:
After @Renchongyi’s reminder, I found that I was wrong. You can set the proxy by setting
HTTP_PROXYor usingnpm config set proxy, but it must be a proxy of thehttpprotocol.Supported proxy configuration
yarn, after the first installation fails, findnpm-pngquant-bin-5.0.2-6f34f3e89c9722a72bbc509062b40f1b17cda460-integrity/node_modules/pngquant-bin/lib/index.jsin the yarn cache, Modify the download source url, modifyraw.githubusercontent.com/imagemintonpm.taobao.org/mirrors, and then reinstall it. Useyarn cache dirto print out the location of yarn cache.pngquant-bin, modify the download source, and publish it to the private server.pngquant-bincan be generated by compilation, but this is not my expertise, so I can’t provide more suggestions.At present, this problem does not appear. Occasionally it appears when initializing “Gatsby”. It can be solved by “brew install lippng”.
Feel very much to you, my friend.
Step1: Find out yarn cache folder ( I was using yarn) by using $yarn cache dir
Step2: Go to “/Users/yourname/Library/Caches/Yarn/v6” and find the “npm-pngquant-bin…” folder and find “…/npm-pngquant-bin-6.0.0-aff0d7e61095feb96ced379ad8c7294ad3dd1712-integrity/node_modules/pngquant-bin/lib/index.js”
Step3: open above index file and change raw.githubusercontent.com/imagemin to npm.taobao.org/mirrors Step4: success!
Great! ”brew install pkg-config“ works!