Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-gyp rebuild fails on Mac OS High Sierra while npm install

I am getting following error in the terminal, while it tries to install one of package "node-expat". I have tried switching to different node version using nvm but still it is failing with same error.

gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/node-expat
npm ERR! node v6.5.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-expat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-expat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-expat
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     c:\<redacted>\npm-debug.log

I went ahead installing x-code as suggested on git hub page, on my machine and then it is giving following error,. Not sure how to debug further.

xcode-select: error: tool 'xcodebuild' requires Xcode, 
but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
like image 790
Luke P. Issac Avatar asked Nov 01 '18 05:11

Luke P. Issac


People also ask

How do I fix node-gyp error on Mac?

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

What is node-gyp in npm?

node-gyp is a cross-platform command-line tool written in Node. js for compiling native addon modules for Node. js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node.

Why npm install is not working?

Broken npm installation If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

Does npm install work on Mac?

You should have some familiarity with the Mac Terminal application since you'll need to use it to install and test Node and NPM. You'll also need the Terminal to use Node. js and NPM. The Terminal application is located in the Utilities folder in the Applications folder.


2 Answers

I just got it fixed on my machine and my fellow colleagues machine.

Followed the following steps to fix it on MacOS highSierra 10.13:

  1. Downloaded command line tools (MacOS 10.13) for xcode and installed it. Download it from "https://developer.apple.com/download/more/"
  2. Installed xcode 10.0 from the app store. Opened xcode and went through the regular configuration xcode does in the initial start up.
  3. After this it started giving "xcode-select" path issue as stated in the description above. On running command "xcode-select --print-path" it was showing path as '/ Library/Developer/CommandLineTools', so i went ahead and tried "xcode-select --reset" after which the path changed to "/Applications/Xcode.app/Contents/Developer". Immediately after it the build started working without any issues.
like image 69
Luke P. Issac Avatar answered Sep 23 '22 00:09

Luke P. Issac


Solution above mentioned by Luke worked partially for me (MacOS) but created another issue : gyp ERR! stack Error:makefailed with exit code: 2 which was solved by removing locked json file. Issue was created due to permission in MAC OS. So if you have xcode re-installed already, open terminal (command line) and type:

xcode-select --reset

then go to your project folder and remove: package-lock.json Now in terminal reinstall project :

npm install

I hope this helps someone!

like image 45
StefaDesign Avatar answered Sep 24 '22 00:09

StefaDesign