npm update出错:pngquant二进制文件似乎无法正常工作

时间:2018-03-15 20:23:29

标签: npm debian pngquant

我的npm update命令出现以下错误:

> pngquant-bin@4.0.0 postinstall /var/www/pp/20180315202846/node_modules/pngquant-bin
> node lib/install.js

  ⚠ The `/var/www/pp/20180315202846/node_modules/pngquant-bin/vendor/pngquant` binary doesn't seem to work correctly
  ⚠ pngquant pre-build test failed
  ℹ compiling from source
  ✔ pngquant pre-build test passed successfully
  ✖ RequestError: pngquant failed to build, make sure that libpng-dev is installed
    at ClientRequest.req.once.err (/var/www/pp/20180315202846/node_modules/pngquant-bin/node_modules/got/index.js:111:21)
    at Object.onceWrapper (events.js:272:13)
    at ClientRequest.emit (events.js:180:13)
    at ClientRequest.onConnect (/var/www/pp/20180315202846/node_modules/pngquant-bin/node_modules/tunnel-agent/index.js:168:23)
    at Object.onceWrapper (events.js:272:13)
    at ClientRequest.emit (events.js:180:13)
    at Socket.socketOnData (_http_client.js:476:11)
    at Socket.emit (events.js:180:13)
    at addChunk (_stream_readable.js:269:12)
    at readableAddChunk (_stream_readable.js:256:11)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pngquant-bin@4.0.0 postinstall: `node lib/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pngquant-bin@4.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我已经做过:

 apt-get install libpng-dev

但我仍然遇到此错误。 有任何想法吗? (我的发行版是Debian 9.2)

4 个答案:

答案 0 :(得分:23)

对于Ubuntu,您需要运行:

wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
  && sudo dpkg -i /tmp/libpng12.deb \
  && rm /tmp/libpng12.deb

答案 1 :(得分:9)

也许您会在原始问题上找到一些帮助。

https://github.com/imagemin/pngquant-bin/issues/78

他是一个建议的解决方案:(复制/粘贴来自:https://github.com/imagemin/pngquant-bin/issues/78#issuecomment-374192838) 正如@ velu76和@ sory19所说,我按照他们的方法:

'sudo apt-get install libpng-dev' 'npm install -g pngquant-bin'

因为我已经在我的repo / project文件夹中'npm install'了,所以我跑了 'sudo rm -rf node_modules'

然后,仍然在我的repository / project文件夹中 'npm install --no-bin-links'

现在它可以正常工作。

我不知道它是否只是一个临时修复,实际上,但我现在可以工作。

答案 2 :(得分:4)

TLDR;
使用node:latest而不是node:alpine for docker image

-
嗨,我正在使用docker image节点:alpine,它昨天也崩溃了。 laravel-mix需要一些外部包装似乎是一个问题。我在节点上测试:高山节点:8.10.0-高山节点:8.8.1-高山无效。我测试了laravel-mix 0.11.4和0.12.1和1.0没有任何作用。但是当我从节点:alpine切换到node:latest时,它可以工作。希望这有帮助

答案 3 :(得分:1)

您可以通过执行以下命令来纠正此错误:

sudo npm install -g name-of-package --unsafe-perm=true --allow-root