Solution for npm install fails with node-gyp error: memory file not found
Short version: Delete Xcode command line tools and reinstall them.
Scenario
Problem:
For a NPM package the dependencies should be installed. NPM install command is run and suddenly fails with an error caused by node-gyp.
Command:
npm install
Output:
Error message:
Fatal error: ‘memory’ file not found
Result:
npm install fails
Context
The npm install command tries to use node-gyp and to build a needed dependency. Node-gyp is complicated, as it is a cross-platform tool for compiling native modules for Node.js. Its readme provides some guidance on how to ensure that it works. The problem start when it should work, but isn’t. Looking at Google, this is a common case.
My computer is a Mac:
For Mac, node-gyp lists the Xcode command line tools as a requirement.
Checking if the tools are installed:
xcode-select --install
Output:
xcode-select: note: Command line tools are already installed. Use “Software Update” in System Settings or the softwareupdate command line interface to install updates
I came across the issue “Can not build on macOS 14.6.1 with clang 16” and answer:
Solution
Delete Xcode command line tools and reinstall them
Remove Xcode Command Line Tools
First, find out the directory where the tools are installed:
xcode-select -p
Result:
/Library/Developer/CommandLineTools
Next: delete the directory. You need to have admin rights!
sudo rm -rf /Library/Developer/CommandLineTools
Running xcode-select to show the installation folder points now to a different one:
xcode-select -p
Result:
/Applications/Xcode.app/Contents/Developer
Installation of Xcode Command Line Tools
Install the tools again:
xcode-select --install
Result:
The Xcode Command Line Tools are installed again.
Result
Running npm install again
npm i
No compile error. Problem solved.
3 Comments
Cormac · October 22, 2024 at 11:38
I just spent three days slowly losing grasp of my sanity while trying in vain to resolve this exact issue before this article saved the day, thank you Tobias!
CaptainCodeman · October 23, 2024 at 23:26
Thank you so much for sharing this, I’ve been going round in circles with this problem!
doesntmatter · November 7, 2024 at 13:31
You saved my day. Thanks bro. I wish you all the best.