安装imagemin-mozjpeg失败
描述
环境:
macOS 12.6 node v14.18.1
1
2yarn add imagemin-mozjpeg
1遇到报错,如下
[4/4] 🔨 Building fresh packages... error /Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/mozjpeg: Command failed. Exit code: 1 Command: node lib/install.js Arguments: Directory: /Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/mozjpeg Output: connect ECONNREFUSED 0.0.0.0:443 mozjpeg pre-build test failed compiling from source Error: Command failed: /bin/sh -c ./configure --enable-static --disable-shared --disable-dependency-tracking --with-jpeg8 libpng_LIBS='/usr/local/lib/libpng16.a -lz' --enable-static --prefix="/Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/mozjpeg/vendor" --bindir="/Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/mozjpeg/vendor" --libdir="/Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/mozjpeg/vendor" configure: error: no nasm (Netwide Assembler) found (太长略过)
1
2
3
4
5
6
7
8
9
10
11
12
13从报错信息来看是
nasm
缺失,怎么解决呢?还得去 issue 看,去这里 (opens new window)。安装相应的包,就可以正常安装了。
# for macOS brew install automake nasm zlib # for Ubuntu sudo apt-get install nasm zlib1g-dev
1
2
3
4
5当然也有人这样安装也是可以的,不过我已经解决上述问题了,就没尝试,这里也贴出来,见issue (opens new window)。
brew install automake autoconf libtool
1后话:
安装 png 插件时遇到类似的问题
yarn add imagemin-pngquant
1
报错如下
error /Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/pngquant-bin: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/pngquant-bin
Output:
connect ECONNREFUSED 0.0.0.0:443
pngquant pre-build test failed
compiling from source
Error: pngquant failed to build, make sure that libpng is installed
at /Users/macbookpro/Documents/app/test/demos/node-test/imagemin-demo/node_modules/execa/index.js:231:11
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Promise.all (index 0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
解决方式也类似,安装就好了。
brew install libpng
1
在 windows 上安装,又出幺蛾子了,所幸有前辈趟坑了,见issue (opens new window)。安装 VC runtime 后 确实管用。
如果还是有问题,试试降低版本:
npm install imagemin-pngquant@5.0.1 --save
npm install pngquant-bin@4.0.0 --save
1
2
3
2
3
上次更新: 2023/01/29, 18:04:46