在 macOS 上安装“imagemin-mozjpeg”时出错:npm ERR!生成未知系统错误-86 | npm 错误! mozjpeg 预构建测试失败

问题描述 投票:0回答:1

我正在使用 macOS Sonoma

v14.4.1
,当我尝试使用以下命令安装
imagemin-mozjpeg
时:

npm i imagemin-mozjpeg

起初我遇到了一些错误,例如

npm ERR! /bin/sh: autoreconf: command not found
,所以我使用
autoconf
安装了
brew

以及其他软件包
brew install autoconf automake libtool

然后我收到另一个错误:““m4”命令需要命令行开发人员工具。”所以我安装了命令行开发工具。

但是之后我遇到了以下一堆错误,我不知道如何修复它们才能成功安装 npm 包

imagemin-mozjpeg

我可能需要先安装一些必备软件包/工具吗?

amjed@192 some-project % npm i imagemin-mozjpeg npm ERR! code 1 npm ERR! path /Users/amjed/some-project/node_modules/mozjpeg npm ERR! command failed npm ERR! command sh -c -- node lib/install.js npm ERR! compiling from source npm ERR! spawn Unknown system error -86 npm ERR! mozjpeg pre-build test failed npm ERR! 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/amjed/some-project/node_modules/mozjpeg/vendor" --bindir="/Users/amjed/some-project/node_modules/mozjpeg/vendor" --libdir="/Users/amjed/some-project/node_modules/mozjpeg/vendor" npm ERR! ./configure: line 14911: PKG_PROG_PKG_CONFIG: command not found npm ERR! ./configure: line 15184: syntax error near unexpected token `libpng,' npm ERR! ./configure: line 15184: `PKG_CHECK_MODULES(libpng, libpng, HAVE_LIBPNG=1,' npm ERR! npm ERR! checking for a BSD-compatible install... /usr/bin/install -c npm ERR! checking whether build environment is sane... yes npm ERR! checking for a race-free mkdir -p... mkdir -p npm ERR! checking for gawk... no npm ERR! checking for mawk... no npm ERR! checking for nawk... no npm ERR! checking for awk... awk npm ERR! checking whether make sets $(MAKE)... yes npm ERR! checking whether make supports nested variables... yes npm ERR! checking whether make supports nested variables... (cached) yes npm ERR! checking whether make supports the include directive... yes (GNU style) npm ERR! checking for gcc... gcc npm ERR! checking whether the C compiler works... yes npm ERR! checking for C compiler default output file name... a.out npm ERR! checking for suffix of executables... npm ERR! checking whether we are cross compiling... no npm ERR! checking for suffix of object files... o npm ERR! checking whether the compiler supports GNU C... yes npm ERR! checking whether gcc accepts -g... yes npm ERR! checking for gcc option to enable C11 features... none needed npm ERR! checking whether gcc understands -c and -o together... yes npm ERR! checking dependency style of gcc... none npm ERR! checking how to run the C preprocessor... gcc -E npm ERR! checking for gcc... (cached) gcc npm ERR! checking whether the compiler supports GNU C... (cached) yes npm ERR! checking whether gcc accepts -g... (cached) yes npm ERR! checking for gcc option to enable C11 features... (cached) none needed npm ERR! checking whether gcc understands -c and -o together... (cached) yes npm ERR! checking dependency style of gcc... (cached) none npm ERR! checking for ar... ar npm ERR! checking the archiver (ar) interface... ar npm ERR! checking dependency style of gcc... none npm ERR! checking the archiver (ar) interface... (cached) ar npm ERR! checking build system type... aarch64-apple-darwin23.4.0 npm ERR! checking host system type... aarch64-apple-darwin23.4.0 npm ERR! checking how to print strings... printf npm ERR! checking for a sed that does not truncate output... /usr/bin/sed npm ERR! checking for grep that handles long lines and -e... /usr/bin/grep npm ERR! checking for egrep... /usr/bin/grep -E npm ERR! checking for fgrep... /usr/bin/grep -F npm ERR! checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld npm ERR! checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no npm ERR! checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B npm ERR! checking the name lister (/usr/bin/nm -B) interface... BSD nm npm ERR! checking whether ln -s works... yes npm ERR! checking the maximum length of command line arguments... 786432 npm ERR! checking how to convert aarch64-apple-darwin23.4.0 file names to aarch64-apple-darwin23.4.0 format... func_convert_file_noop npm ERR! checking how to convert aarch64-apple-darwin23.4.0 file names to toolchain format... func_convert_file_noop npm ERR! checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r npm ERR! checking for file... file npm ERR! checking for objdump... objdump npm ERR! checking how to recognize dependent libraries... pass_all npm ERR! checking for dlltool... no npm ERR! checking how to associate runtime and link libraries... printf %s\n npm ERR! checking for archiver @FILE support... no npm ERR! checking for strip... strip npm ERR! checking for ranlib... ranlib npm ERR! checking command to parse /usr/bin/nm -B output from gcc object... ok npm ERR! checking for sysroot... no npm ERR! checking for a working dd... /bin/dd npm ERR! checking how to truncate binary pipes... /bin/dd bs=4096 count=1 npm ERR! checking for mt... no npm ERR! checking if : is a manifest tool... no npm ERR! checking for dsymutil... dsymutil npm ERR! checking for nmedit... nmedit npm ERR! checking for lipo... lipo npm ERR! checking for otool... otool npm ERR! checking for otool64... no npm ERR! checking for -single_module linker flag... ld: warning: -single_module is obsolete npm ERR! no npm ERR! checking for -exported_symbols_list linker flag... yes npm ERR! checking for -force_load linker flag... yes npm ERR! checking for stdio.h... yes npm ERR! checking for stdlib.h... yes npm ERR! checking for string.h... yes npm ERR! checking for inttypes.h... yes npm ERR! checking for stdint.h... yes npm ERR! checking for strings.h... yes npm ERR! checking for sys/stat.h... yes npm ERR! checking for sys/types.h... yes npm ERR! checking for unistd.h... yes npm ERR! checking for dlfcn.h... yes npm ERR! checking for objdir... .libs npm ERR! checking if gcc supports -fno-rtti -fno-exceptions... yes npm ERR! checking for gcc option to produce PIC... -fno-common -DPIC npm ERR! checking if gcc PIC flag -fno-common -DPIC works... yes npm ERR! checking if gcc static flag -static works... no npm ERR! checking if gcc supports -c -o file.o... yes npm ERR! checking if gcc supports -c -o file.o... (cached) yes npm ERR! checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes npm ERR! checking dynamic linker characteristics... darwin23.4.0 dyld npm ERR! checking how to hardcode library paths into programs... immediate npm ERR! checking whether stripping libraries is possible... yes npm ERR! checking if libtool supports shared libraries... yes npm ERR! checking whether to build shared libraries... no npm ERR! checking whether to build static libraries... yes npm ERR! checking whether ln -s works... yes npm ERR! checking size of size_t... 8 npm ERR! checking whether compiler supports pointers to undefined structures... yes npm ERR! checking for gcc options needed to detect all undeclared functions... none needed npm ERR! checking whether __SUNPRO_C is declared... no npm ERR! checking for pow in -lm... yes npm ERR! npm ERR! at /Users/amjed/some-project/node_modules/execa/index.js:231:11 npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:95:5) npm ERR! at async Promise.all (index 0) npm ERR! A complete log of this run can be found in: npm ERR! /Users/amjed/.npm/_logs/2024-05-09T17_02_52_801Z-debug-0.log
    
node.js npm mozjpeg
1个回答
0
投票
对于将来遇到此问题的任何人,下面是为我解决问题的命令。

帮助我解决此问题的有用资源

  • https://github.com/imagemin/imagemin/issues/168
  • https://github.com/imagemin/mozjpeg-bin/issues/64
  • 构建要求:
  • https://github.com/mozilla/mozjpeg/blob/da75d56d6c71fcf33cca2118065af13409fe35d4/BUILDING.txt
所以正如我在问题中提到的,我首先跑了

brew install autoconf automake libtool
然后打开一个提示,要求我安装命令行开发人员工具,我单击了该提示上的“安装”按钮。否则,您可以通过运行以下命令手动安装它:

注意确保将以下命令中的

1.4.19

 替换为您安装的 
m4
 版本

xcode-select --install
然后我也在下面运行以将 

m4

 设置为路径

export PATH="/opt/homebrew/Cellar/m4/1.4.19/bin:$PATH"
然后我就跑

brew install dpkg pkgconfig nasm libpng
然后我在 

/usr/local/lib

libpng16.a
 中创建了一个符号链接

注意确保将以下命令中的

1.6.43

 替换为您安装的 
libpng
 版本

sudo ln -s /opt/homebrew/Cellar/libpng/1.6.43/lib/libpng16.a /usr/local/lib/libpng16.a
最后我使用 npm 重新安装了

imagemin-mozjpeg

,终于成功了!

npm i imagemin-mozjpeg
    
© www.soinside.com 2019 - 2024. All rights reserved.