Eric Guo's blog.cloud-mes.com

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Resolving macOS Ventura Failed to Install Npm Package Sharp After Brew Upgrade Vips to 8.15.0_1

Permalink

sharp is a dependency module for Next.js. However, I encountered an installation error on my MacOS Ventura, as shown below:

error /Users/guochunzhong/git/sso/changelog/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments:
Directory: /Users/guochunzhong/git/sso/changelog/node_modules/sharp
Output:
sharp: Detected globally-installed libvips v8.15.0
sharp: Building from source via node-gyp
gyp info it worked if it ends with ok
gyp info using node-gyp@10.0.1
gyp info using node@18.18.2 | darwin | arm64
gyp info find Python using Python version 3.11.6 found at "/opt/homebrew/opt/python@3.11/bin/python3.11"
gyp info spawn /opt/homebrew/opt/python@3.11/bin/python3.11
gyp info spawn args [
gyp info spawn args '/opt/homebrew/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/Users/guochunzhong/git/sso/changelog/node_modules/sharp/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/opt/homebrew/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/guochunzhong/Library/Caches/node-gyp/18.18.2/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/guochunzhong/Library/Caches/node-gyp/18.18.2',
gyp info spawn args '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/guochunzhong/Library/Caches/node-gyp/18.18.2/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/Users/guochunzhong/git/sso/changelog/node_modules/sharp',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
Package libarchive was not found in the pkg-config search path.
Perhaps you should add the directory containing `libarchive.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libarchive', required by 'vips', not found
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
LIBTOOL-STATIC Release/nothing.a
warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
TOUCH Release/obj.target/libvips-cpp.stamp
CXX(target) Release/obj.target/sharp-darwin-arm64v8/src/common.o
../src/common.cc:13:10: fatal error: 'vips/vips8' file not found
#include <vips/vips8>
^~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/sharp-darwin-arm64v8/src/common.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/node-gyp/lib/build.js:209:23)
gyp ERR! System Darwin 22.6.0
gyp ERR! command "/opt/homebrew/Cellar/node@18/18.18.2/bin/node" "/opt/homebrew/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/guochunzhong/git/sso/changelog/node_modules/sharp
gyp ERR! node -v v18.18.2
gyp ERR! node-gyp -v v10.0.1
gyp ERR! not ok
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.

This issue can be resolved by executing the following command: export PKG_CONFIG_PATH=/opt/homebrew/Cellar/libarchive/3.7.2/lib/pkgconfig:/opt/homebrew/Cellar/vips/8.15.0_1/lib/pkgconfig

This solution was suggested by GPT-4!

Comments