Skip to content

node-gyp issues in Windows

I recently encountered issues with node-gyp on my Windows machine, which prevented me from doing any productive typescript/node development. It gave out the following error message:

node-gyp Error: Cannot find module C:\Users\Asus\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

node-gyp is a low level module dependency used by npm used for compiling native addon modules for Node.js. Generally, most node developers don’t really encounter it, until this issue pops up.

One of my symptoms for this issue was not being able to run npm install , resulting to the above error.

Diagnosis

My understanding of the problem is that somewhere in my configuration of npm in my machine, it failed to locate the node-gyp code. Reviewing internet forums and such, it recommended me certain solutions that required me to install some dependency X using npm install X , but my problem altogether was that npm install wasn’t working.

Resolution

After some trial and error, i was able to fix this issue on my Windows machine following this train of thought:

  1. I need to have all the files necessary to run node and npm so I downloaded the latest Node installer for Windows.
  2. I ran the installer.
  3. At this point, I tried to see if npm worked correctly. It didn’t. The node-gyp issue is still not resolved.
  4. I tried to figure out which npm command is running on my machine. I did this by typing npm -l. This describes the location of the npm program.
Result of running npm -l on your command line.
  1. Go to that directory. Mine was C:\Users\Darren\AppData\Roaming.
  2. In that directory, I deleted the whole npm subfolder (Note that this was C:\Users\Darren\AppData\Roaming\npm).
  3. Now that I have missing files, I need to get the complete set of files that I am missing. Run the installer in step 1, to repair missing files and registry settings.
  4. Once finished, I ran npm install -g npm.

At this point, I’ve fixed my npm install issues. I shared my findings as well in this GitHub issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.