Recurring gyp build failure during npm install on macOS Mojave system

Hey everyone! I keep running into this frustrating issue whenever I try to install packages with npm on my Mac. The build process keeps failing and I can’t figure out what’s going wrong.

I’ve already tried a few different approaches like using the build-from-source flag and installing the gyp tools globally, but nothing seems to work. The error always happens when it tries to compile native modules.

Here’s what I’m seeing in my terminal:

gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:289:45)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/johnsmith/Projects/react-app/node_modules/watchpack/lib/binding/Release/node-v72-darwin-x64/watcher.node" "--module_name=watcher" "--module_path=/Users/johnsmith/Projects/react-app/node_modules/watchpack/lib/binding/Release/node-v72-darwin-x64"
gyp ERR! cwd /Users/johnsmith/Projects/react-app/node_modules/watchpack
gyp ERR! node -v v10.16.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
make: *** [Release/obj.target/watcher/filewatcher.o] Error 1

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/watchpack):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node compile`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 892 packages from 521 contributors and audited 9834 packages in 52.14s
found 421 vulnerabilities (298 low, 98 moderate, 24 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

Anyone know how to solve this problem?

i was in the same boat on mojave last month. try running xcode-select --install again, even if u think u already did it. also check your python version - gyp needs 2.7 and gets messed up with python 3.

Had this same error on Mojave with older Node versions. Your Node v10.16.2 and node-gyp v3.8.0 are too outdated - that’s what’s causing the build tool conflicts. Here’s what fixed it for me: upgrade to a recent LTS Node version, run npm cache clean --force, delete node_modules and package-lock.json, then reinstall everything. The newer versions play much better with macOS build chains and killed those watchpack errors.

Classic Xcode command line tools mismatch. Had the same thing happen after updating to Mojave - the CLI tools got corrupted during the OS upgrade. Here’s what fixed it for me: completely nuke the existing tools first with sudo rm -rf /Library/Developer/CommandLineTools, then do a fresh install with xcode-select --install. Also check if you’ve got multiple Xcode installations fighting each other by running xcode-select -p to see which one’s active. Watchpack needs native compilation to work, so any toolchain problems will break it exactly like this.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.