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:
- I need to have all the files necessary to run
node
andnpm
so I downloaded the latest Node installer for Windows. - I ran the installer.
- At this point, I tried to see if
npm
worked correctly. It didn’t. Thenode-gyp
issue is still not resolved. - I tried to figure out which
npm
command is running on my machine. I did this by typingnpm -l
. This describes the location of thenpm
program.
- Go to that directory. Mine was
C:\Users\Darren\AppData\Roaming
. - In that directory, I deleted the whole
npm
subfolder (Note that this wasC:\Users\Darren\AppData\Roaming\npm
). - 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.
- 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