Fix broken ‘node-gyp’ issue for Mac OS
This issue is usually caused because a node-gyp
config file called common.gypi
is not set up for your current Mac OS version.
It often times comes accompanied with an error message like:
fatal error: 'utility' file not found
#include <utility>
Another usual fix is to reinstall XCode’s command-line tools with:
$ xcode-select --install
Just for context, this issue usually happens after upgrading your OS of if you use nvm
and are using a newly installed NodeJs version.
If your project has any complex dependencies that rely heavily on native libraries this solution might not be for you.
If the most complex node-gyp
-related dependency you have in your project is something common like node-sass
then this is usually the fix you need.
You’ll need to find and edit the common.gypi
file for the NodeJs version you’re using. You’ll usually find it in a path like:
~/.node-gyp/<your_node_version_here>/include/node/common.gypi
Example for NodeJs 6.5.0:
~/.node-gyp/6.5.0/include/node/common.gypi
(Remember
~
means your user’s$HOME
directory)
Open the file, find the MACOSX_DEPLOYMENT_TARGET
key value and replace it with your current Mac OS version (10.15.3
for Catalina for example).
Examples with different editors:
Using nano
The most underrated editor ever:
$ nano ~/.node-gyp/<your_node_version_here>/include/node/common.gypi
Using VS Code
Yes you can also use it to edit shady config files, just Save the file as usual when you’re done.
$ code ~/.node-gyp/<your_node_version_here>/include/node/common.gypi
(Remember this is under $HOME
so the command doesn’t require any special permissions like sudo)
Using vim
(But why? Odds are you’re already having a shitty day with node-gyp):
$ vim ~/.node-gyp/<your_node_version_here>/include/node/common.gypi
Pro-tip: To exit hit
Esc
and then:wq!
and thenEnter
.
w
is for write,q
for quit and!
to express you’re happy to be free again!Just kidding, it’s to force the operation.
If this doesn’t work
Here are some related Github issues and Stack Overflow posts that might help:
- Why is node-gyp rebuild failing on Mac OSX El Capitan — Stack overflow
- nodejs/node-gyp: node-gyp rebuild Fails on Mac OS X 10.9.4 - Github
- nodejs/node-gyp: node-gyp rebuild fails in macOS Catalina (10.15) — No rule to make target `node_modules/node-gyp/addon.gypi`, needed by `Makefile`- Github
- nodejs/node-gyp: node-gyp rebuild failed on MacOS — Github