You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Sonoma v14.4.1安装imagemin-mozjpeg失败求助

问题描述

在 macOS Sonoma v14.4.1 环境下执行 npm i imagemin-mozjpeg 安装依赖时遇到以下问题:

  • 初始报错 npm ERR! /bin/sh: autoreconf: command not found,通过 brew install autoconf automake libtool 解决
  • 安装命令行开发工具后,仍出现多个错误:
    • spawn Unknown system error -86
    • mozjpeg pre-build test failed
    • configure 脚本报错:PKG_PROG_PKG_CONFIG: command not found、syntax error near unexpected token 'libpng,'

报错详情:

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
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
解决方案

针对报错中的关键问题,按以下步骤安装依赖并调整环境:

  • 安装 pkg-config
    报错中的 PKG_PROG_PKG_CONFIG: command not found 说明缺少 pkg-config 工具,执行:

    brew install pkg-config
    
  • 安装 libpng 依赖
    configure 脚本中检测 libpng 失败,需要安装对应库:

    brew install libpng
    
  • 处理 Apple Silicon 架构兼容问题
    spawn Unknown system error -86 是典型的架构不兼容错误(预编译二进制为 x86_64,而你的系统是 arm64),可以通过以下两种方式解决:

    1. 用 Rosetta 运行终端:找到「终端」应用,右键选择「显示简介」,勾选「使用 Rosetta 打开」,重启终端后再执行 npm i imagemin-mozjpeg。
    2. 指定编译架构:在执行安装命令前设置环境变量,强制编译 arm64 版本:
      export CFLAGS="-arch arm64"
      export CXXFLAGS="-arch arm64"
      npm i imagemin-mozjpeg
      
  • 清理缓存后重新安装
    安装完依赖后,清理 npm 缓存避免残留问题:

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm i imagemin-mozjpeg
    

内容的提问来源于stack exchange,提问作者Amjed Omar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 03:54:50