使用Metaplex搭建Solana Candy Machine时执行yarn install遇node-gyp错误的解决咨询
Yep, this issue is definitely tied to node-pre-gyp and the canvas package's system-level dependencies. Here's what's going on:
The canvas package (a dependency of Metaplex CLI) relies on node-pre-gyp to fetch precompiled binary files for your system. If that download fails (due to network issues, version mismatches, or missing system tools), it falls back to compiling from source using node-gyp—which requires specific build tools and libraries that aren't installed by default on macOS.
Here's how to fix this step-by-step:
1. Install macOS Build Tools
First, make sure you have Xcode Command Line Tools installed (these are required for compiling native modules):
xcode-select --install
Follow the on-screen prompts to complete the installation.
2. Install System Dependencies for canvas
Use Homebrew (install it first if you haven't already) to install the libraries canvas needs to compile:
# Install Homebrew if you haven't already /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install canvas dependencies brew install pkg-config cairo pango libpng jpeg giflib librsvg
3. Clean Cache and Reinstall Dependencies
Clear any corrupted cache or partial installs, then start fresh:
# Navigate to your Metaplex CLI directory cd /Users/yohan/metaplex/js/packages/cli # Clear yarn cache yarn cache clean # Remove existing node_modules and lock files rm -rf node_modules rm -f yarn.lock package-lock.json # Reinstall dependencies yarn install
4. Fallback: Force Source Compilation (If Needed)
If the above steps still fail, you can force node-pre-gyp to compile from source instead of trying to download prebuilt binaries:
npm_config_build_from_source=true yarn install
This should resolve the gyp ERR! and node-pre-gyp ERR! errors you're seeing, since it ensures all required tools and libraries are present for the canvas package to build successfully.
内容的提问来源于stack exchange,提问作者하얀병아리

