安装Gatsby Starter时sharp依赖安装失败,求解决方案
Hey there, let's get this sorted out! The error you're hitting happens because your Mac system is missing the libffi library—something the sharp package (a dependency of favicons) needs to build successfully. Here's a step-by-step fix:
First, update Homebrew to make sure you're working with the latest package versions:
brew updateInstall the missing
libffilibrary using Homebrew:brew install libffiNext, tell
pkg-configwhere to find the libffi configuration file by setting the environment variable:export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"Note: If you use zsh, add this line to your
~/.zshrcfile so it persists across terminal sessions. For bash, add it to~/.bash_profile.Clean up your existing installation files to avoid leftover conflicts:
rm -rf node_modules rm package-lock.jsonFinally, reinstall your project dependencies from scratch:
npm install
If you still run into issues after these steps, try reinstalling sharp directly with force to ensure it builds correctly:
npm install sharp --force
To give a bit of context: The error log calls out "Package 'libffi', required by 'gobject-2.0', not found"—this means the sharp build process couldn't locate the libffi library, which is a critical dependency for gobject-2.0. By installing libffi and updating the pkg-config path, we're giving the build tool exactly what it needs to compile sharp successfully.
内容的提问来源于stack exchange,提问作者Wing Cheung Kwok

