Fixing NPM – “pngquant failed to build, make sure that libpng-dev”

If you are reading this you probably have seen an error message similar to what is below. The key part is “libpng-dev”, which, “is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.” – libpng-dev

‼ pngquant pre-build test failed
    i compiling from source
EXEC : × error : pngquant failed to build, make sure that libpng-dev is installed [C:\...\_work\1\s\src\Web\Web.csproj]
      at C:\...\_work\1\s\src\Web\node_modules\execa\index.js:231:11
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Promise.all (index 0)
...
npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! pngquant-bin@5.0.2 postinstall: `node lib/install.js`
  npm ERR! Exit status 1
  npm ERR! 
  npm ERR! Failed at the pngquant-bin@5.0.2 postinstall script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Use .NET Core version 3.1.100

For my specific case, I had to have everything install in an automated fashion using silent installs and getting feedback on installs status.

If you just want to the solution here it is, to understand how this became the solution keep reading.


powershell.exe -NoProfile ^
 -InputFormat None  ^
 -ExecutionPolicy Bypass  ^
 -Command Start-Process 'powershell.exe'  ^
  -ArgumentList '-NoProfile -InputFormat None -ExecutionPolicy Bypass  ^
  -Command iex ((New-Object System.Net.WebClient).DownloadString(''https://chocolatey.org/install.ps1''));  ^
    choco upgrade -y python visualstudio2017-workload-vctools; ' -Verb RunAs

I first tried the npm package “winodws-build-tools”.

npm install --global windows-build-tools

While this works for manual installs, it hung for me which was forcing the automation script to not complete – see links in the footer for more discussion around this. So cant use this…

Then I remembered that the Node.js MSI includes an option to these tools/compilers that are needed to compile the native addons.

This should be very similar to the above windows-build-tools. Since i need a silent install and I could not find now a way to set this flag from msiexec. I tried to run the opensource WixToolset.Dtf project to attempt at reading the MSI database to find the command line argument to pass in. That failed, but could easily have been miss reading the data since MSI packaging is unfamiliar to me.

msiexec /qn /l* node-log.txt /i node-v12.16.1-x64.msi;

Next, I figured id open the node-v12.16.1-x64.msi archive and see what I could discover there. You can see in the image below there is a file called InstallToolsBat.

This uses chocolatey to install python and visualstudio2017-workload-vctools. So I modified that and used it in my automation script.

The final working solution was:

powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command Start-Process '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe' -ArgumentList '-NoProfile -InputFormat None -ExecutionPolicy Bypass -Command iex ((New-Object System.Net.WebClient).DownloadString(''https://chocolatey.org/install.ps1'')); choco upgrade -y python visualstudio2017-workload-vctools; ' -Verb RunAs

You might also find some of the solutions proposed in this blog post helpful or the links at the end of this post.

This article is based on Windows:

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      18363  0

Further Reading:

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *