Post

Fix Gyp Error with NVM

Try this if you cant run npm install because you keep getting gyp ERR!

firstly, what is node-gyp?

node-gyp is a cross-platform command-line tool used for compiling native add-on modules for Node.js. It acts as a build system for projects that involve C/C++ code integration with Node.js. This is necessary when npm packages need to run C++ code, such as when they provide bindings to native libraries or perform computationally intensive tasks. node-gyp works by using Python and system-specific build tools (like Make for Linux or MSBuild for Windows) to compile the source code into a format that can be used by Node.js.

Key points about node-gyp:

  • It requires Python (usually Python 3.x).
  • On Windows, it requires Visual Studio and related build tools.
  • It’s often invoked automatically during npm install when a package has native dependencies.

If you’re getting errors related to node-gyp, they often stem from missing build tools, incompatible Node.js versions, or system configuration issues.

You can try some of these methods to fix the annoying Gyp error.

1. Change your node version

For most stability, try using Node.js LTS (Long-Term Support) 16.x or 18.x

Prerequisites

NVM (node version manager) is installed

Check your node version

1
node -v

Change your node version

1
nvm use 16.0

Install different versions of node using NVM

1
2
3
nvm install 16.0
nvm use 16.0
node -v

2. Remove the dependency on gyp.

Find the dependency that depends on gyp and remove it from your package.json file. Then run npm install.

Find the package depending on GYP.

Commands like this will try find it for you but might not find it.

1
npm ls node-gyp

Macosx

node-gyp also requires x-code command line tools to be installed.

Reinstall the package

Now you can install that package that relied on gyp.

When you run npm install after cloning a repo and you get the gyp ERR! not ok this error can be caused by the node version you are running.

3. Upgrade npm

Sometimes, updating npm to the latest version can resolve issues related to node-gyp:

1
npm install -g npm
This post is licensed under CC BY 4.0 by the author.