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'.

  • Node Version: 10.10.0 / 6.4.1
  • Platform: Darwin Matts-MBP-3.local 19.0.0 Darwin Kernel Version 19.0.0: Fri May 24 17:36:10 PDT 2019; root:xnu-6041.0.0.111.5~1/RELEASE_X86_64 x86_64
  • Compiler: Apple clang version 11.0.0 (clang-1100.0.20.17) Target: x86_64-apple-darwin19.0.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • Module: Failure occurred during better-sqlite3@5.4.0 install as part of electron-builder
Verbose output (from npm or node-gyp):
> electron-builder install-app-deps --arch x64

  • electron-builder version=20.26.1
  • rebuilding native production dependencies platform=darwin arch=x64
Error: /usr/local/Cellar/node/10.10.0/bin/node exited with code 1
Output:

> better-sqlite3@5.4.0 install /Users/mattcowley/WebstormProjects/MagicCap/node_modules/better-sqlite3
> node-gyp rebuild


Error output:
make: *** No rule to make target `../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', needed by `Makefile'.  Stop.
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/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 19.0.0
gyp ERR! command "/usr/local/Cellar/node/10.10.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/mattcowley/WebstormProjects/MagicCap/node_modules/better-sqlite3
gyp ERR! node -v v10.10.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! better-sqlite3@5.4.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the better-sqlite3@5.4.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mattcowley/.npm/_logs/2019-06-16T10_20_00_103Z-debug.log

    at ChildProcess.childProcess.once.code (/Users/mattcowley/WebstormProjects/MagicCap/node_modules/builder-util/src/util.ts:255:14)
    at Object.onceWrapper (events.js:273:13)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:962:16)
    at Socket.stream.socket.on (internal/child_process.js:381:11)
    at Socket.emit (events.js:182:13)
    at Pipe._handle.close (net.js:606:12)
From previous event:
    at rebuild (/Users/mattcowley/WebstormProjects/MagicCap/node_modules/app-builder-lib/out/util/yarn.js:238:18)
    at /Users/mattcowley/WebstormProjects/MagicCap/node_modules/app-builder-lib/src/util/yarn.ts:20:11
From previous event:
    at installOrRebuild (/Users/mattcowley/WebstormProjects/MagicCap/node_modules/app-builder-lib/out/util/yarn.js:68:17)
    at /Users/mattcowley/WebstormProjects/MagicCap/node_modules/electron-builder/src/cli/install-app-deps.ts:56:9
    at Generator.next (<anonymous>)
    at runCallback (timers.js:694:18)
    at tryOnImmediate (timers.js:665:5)
    at processImmediate (timers.js:647:5)
From previous event:
    at installAppDeps (/Users/mattcowley/WebstormProjects/MagicCap/node_modules/electron-builder/out/cli/install-app-deps.js:174:17)
    at then (/Users/mattcowley/WebstormProjects/MagicCap/node_modules/electron-builder/src/cli/cli.ts:42:48)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! magiccap@1.1.0-b4 postinstall: `electron-builder install-app-deps --arch x64`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the magiccap@1.1.0-b4 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mattcowley/.npm/_logs/2019-06-16T10_20_00_173Z-debug.log

2019-06-16T10_20_00_103Z-debug.log

2019-06-16T10_20_00_173Z-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 62 (14 by maintainers)

Most upvoted comments

Same issue occurs if node-gyp is forced to 5.0.0 in the package by doing npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"

Upon opening Xcode I noticed the location for the Command Line Tools were empty. (Preferences > Locations). After selecting the tools there, I could run the install.

Hey @jonbondani, before doing any of the following steps I outline, make sure you have updated xcode, and opened xcode, so it can install the most recent compiler tools. If you haven’t done this node-gyp won’t be able to compile correctly. For me though, even after I installed the latest version of xcode, I still had the same issue. The issue happens because parts of / are now read only in Catalina, which has been causing issues for node-gyp. According to the issue referenced in this thread though, the issue should be fixed now.

In the end, this is what worked for me:

  1. Using brew, uninstalled node and yarn.
  2. Installed NVM [https://github.com/nvm-sh/nvm].
  3. Installed a version of Node through NVM, and configured it to be my global default.
  4. Reinstalled yarn
  5. Removed the ‘node_modules’ directory for my project, and then ran ‘yarn install’ to pull in everything I needed again from my package.json

As a note, one benefit you get from switching to NVM is the ability to add a .nvmrc to your project, which locks it to a specific node version.

I’m running Mac OS Catalina and encountered this issue. I was installing node-memwatch for my node application.

I’ve tried reinstalling using installer from the official website & brew install node

The error still popped up. My workaround was installing node using nvm instead. I still do not have an idea what actually causes the issue though.

Removing package-lock.json and running npm install worked for me.

That’s true for me. I already had the xcode tools installed and didn’t know why it was falling. It was a project that a coworker initialized on MS Windows. Running the following worked for me:

rm -rf node_modules package-lock.json
npm i

In case it helps someone: I still got the error although Xcode was installed on my machine. It works after executing `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer.

@rvagg This isn’t an issue with electron builder. Simply running npm i integer raises the same failure.

Same issue occurs if node-gyp is forced to 5.0.0 in the package by doing npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"

solve my problem ,thanks

This issue seems to have ran its course. For people coming here through search engines: see https://github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md

Upon opening Xcode I noticed the location for the Command Line Tools were empty. (Preferences > Locations). After selecting the tools there, I could run the install. Thank you so much @hphoeksma. your solution solved my problem.

Removing package-lock.json and running npm install also worked for me. Don’t know why, but it does not seem to be a stable solution. I would go with nvm.

Removing package-lock.json and running npm install worked for me.

That’s true for me. I already had the xcode tools installed and didn’t know why it was falling. It was a project that a coworker initialized on MS Windows. Running the following worked for me:

rm -rf node_modules package-lock.json
npm i

Thank bro, I have fixed my issue with this suggest

Removing package-lock.json and running npm install worked for me.

The err I got was not entirely the same, but here is a possible fix (worked for me).

Just removing package lock (or yarn lock) and doing npm i got rid of the err for me. npm i runs without errors now.

I installed node via brew. node -v: v12.12.0

I’m running into this exact same issue. Even with the reference to weak-napi… I have tried using Node 10.x and 8.x to no avail. Just continually getting errors. Does anybody have any solutions for this problem or troubleshooting tips? For what its worth I have NOT upgraded to Catalina yet.

In reference to my own comment…

npm install --python=python2 / python2.7 / python2.7.16, etc was not working.

I manually ran pyenv shell 2.7.16 and then ran npm install and it worked.

Hooray I suppose, still not sure why this issue started randomly for me.

@cclauss I tied both of the methods you listed, before switching to NVM, without success.

I want to restate that support for Catalina is a low priority until it’s in (or closer to) GA. But we can certainly collect more data on it. I’m certainly not going to jump onto the Catalina train until GA so it’s going to be up to you early adopters that are willing to deal with breakage like this and yak shave your way to fixes.

@Boxonical can you paste some output for your failed node-memwatch? Is it the same make: *** No rule to make target …/…/…/…/…/…/…/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi’, needed by Makefile'. Stop. error?

The fact that it works from nvm is interesting because you’re getting an entirely different pathing structure to the global / npm node_modules directory. Given Apple’s propensity to screw with /usr/local I’m wondering if they’ve done something else funky with that that’s messing up relative pathing into there.

So, for anyone that wants to help solve this, try this:

When you get an error output that starts with something like this:

> integer@2.1.0 install /Users/mattcowley/WebstormProjects/MagicCap/node_modules/integer
> node-gyp rebuild

and then yields a failure like this:

make: *** No rule to make target `../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', needed by `Makefile'.  Stop.

cd into that first directory, e.g. /Users/mattcowley/WebstormProjects/MagicCap/node_modules/integer and do an ls ../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi using that second path that fails, and see if it resolves. Also try a realpath on that same path to see what it resolves to as an absolute non-linked path. If you’re getting errors or weird results from that, mess around with that relative path a bit and see how you can make it work properly. That won’t tell us how to fix it here (exactly) but it might give us a hint for how to approach it.

@eranhr You’re probably using an old version of node-gyp / node-pre-gyp.

Make sure your dependencies/resolutions are using a recent version.

I use yarn and always add something like this:

  "resolutions": {
    "node-gyp": "^6.1.0",
    "node-pre-gyp": "^0.14.0"
  }

If you’re using npm instead of yarn, you can use npm-force-resolutions to use the same kind of forced dependency resolution behavior as yarn.

One of the major benefits and major pitfalls of JS ecosystem is version pinning - however that sometimes results in old packages that don’t ever get upgraded to use new versions of critical packages such as this.

Sorry I’m unable to recreate the issue ever since I use nvm to workaround.

I’ve tried:

  1. uninstall nvm & node
  2. npm install using homebrew / official installer without nvm, attempting to recreate but node-memwatch installed successfully without errors

Prior to workaround I did encountered the same error make: *** No rule to make target ../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi, needed by Makefile. Stop.

I’m more convinced this is a node pathing issue instead of package (integer / node-memwatch) issue

I found this elsewhere and I have no idea what it does, but I deleted package-lock.js and package.js files and then ran this:

npm i -g node-gyp@latest && npm config set node_gyp “/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js”

And for some reason, that seems to have worked. When I tried to clone the same repo in a new directory and install it again, it was broken again with the same errors. Maybe I need to run that line of code every single time (??) but I’m afraid to do it again and break that one repo I got working in the first directory.

EDIT: someone helped me by pointing out node-sass causes a lot of node-gyp errors. To fix it, I just had to install node-sass independently first before running ‘node install’ because it has tight native bindings to the version of Node you’re using.

Spent tens of hours trying to solve it (not successful). So I have decided to dive into JS and Py code for debugging. under /usr/local/lib/node_modules/node-gyp/lib/configure.js line # 299 i found this: var nodeLibFile = path.join(nodeDir, !gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)', release.name + '.lib') which caused me some problems (not sure if this is the right syntax for template strings in JS…). It resulted the args array (passed to py scripts) to include the following item:

-Dnode_lib_file=/Users/josh/Library/Caches/node-gyp/12.13.1/<(target_arch)/node.lib’,

obviously .../<(target_arch)/... is not a valid path (it was supposed to be replaced with gyp.opts - arguments/options from terminal).

I don’t understand how it worked for others if there is an internal error in the core lib of node-gyp

Same issue occurs if node-gyp is forced to 5.0.0 in the package by doing npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"

Thanks buddy

I solved the issue on my 16" MBP (clean Catalina install) by opening XCode, manually selecting the CLI install directory from the locations tab in preferences, then downgrading to node V11 using NVM.

I tried everything in this thread as well as the documentation posted by @cclauss but my issue was the my git repo local directory had a space in it “git repos”. After removing the space I was able to install correctly. It appears that gyp doesn’t handle spaces in git repository names very well.

the error I was seeing: as you can see the directory starts with ‘repos’ and not ‘git repos’:

clang: error: no such file or directory: 'repos/outlook-web-addin/node_modules/node-addon-api'
make: *** [Release/obj.target/weakref/src/weakref.o] Error 1
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/npm-lifecycle/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:223:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/amcinerney/Documents/git repos/outlook-web-addin/node_modules/weak-napi
gyp ERR! node -v v12.14.1
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok 

Upon opening Xcode I noticed the location for the Command Line Tools were empty. (Preferences > Locations). After selecting the tools there, I could run the install.

This from @hphoeksma comment and removing package-lock as @joshuabaker said fix it for me

@jonbondani wrote:

I’ve reinstalled xcode comandtools

This is not all of Xcode so my bet is that xcodebuild -version only returned a message about xcode-select. If this is the case, and if Jon wishes to avoid installing all of Xcode then run the commands at https://github.com/nodejs/node-gyp/issues/1927#issuecomment-544961544 until com.apple.pkg.CLTools_Executables appears.

TypeError: cannot use a string pattern on a bytes-like object is Python 3 complaining about an incomplete port. Python 2 made no distinction between bytes and str but Python 3 strictly enforces that distinction. A quick fix would be use Python 2 for the install.

Realpath doesn’t give any useful clues

realpath /Users
/Users

However i have found a workaround that solves the problem of node-gyp, by setting the config directories of npm to a different directory that doesn’t have the problem, like /opt:

sudo mkdir /opt/node
sudo chown {user}: /opt/node
npm config set devdir /opt/node/npm 
npm config set prefix /opt/node/npm-global
export PATH=~/opt/node/npm-global/bin:$PATH

I fixed this by upgrading sharp in package.json. It’s worth going through any packages that might be requiring node-gyp and making sure they’re up to date.

This worked for me. I noticed that xcodebuild was not available on the command line. I ended up needing too enable command line tools Under Xcode > Preferences > Locations

See the following, https://stackoverflow.com/questions/24445229/why-is-xcodebuild-command-not-found-in-this-build-script

@theigor cuz does not work for everybody, in my case the acid tests pass but I still got the issue

@hphoeksma thanks a lot!

make sure you have updated Xcode, and opened Xcode, so it can install the most recent compiler tools

There are TWO ways to do this:

  1. Install all of Xcode (7.6 GB of download and disk space) --or–
  2. Xcode-select Command Line Tools (This is what homebrew uses.) See #1927

Both work but both have their idiosyncrasies.