question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module 'C:\...\node-gyp\bin\node-gyp.js'

See original GitHub issue

Hi! I’m trying to use node-gyp but when I call node-gyp in shell it throws me this error

if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" build )  else (node "" build )
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
←[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:725:27)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: []
}

What should I do? I tried to install windows-build-tools originally npm i -g windows-build-tools it installs for eternal but npm i -g windows-build-tools@4.0.0 works

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
owl-from-hogvartscommented, May 5, 2021

another my guess is that, as i saw, you have added wrong node-gyp to your PATH variable: you have added node-gyp from internals of npm, but not from global node_moduels location (by default %APPDATA%\npm). When you have run node-gyp it has executed node-gyp from internals of npm and because npm uses magical node-gyp.cmd to launch the node-gyp itself, you got such strange error.

The solution is:

  1. press Win + R
  2. type SystemPropertiesAdvanced.exe and press Enter
  3. press Environment Variables button in bottom right corener of the window
  4. select Path var in User variables area and press Edit
  5. find row which contain appdata\roamning\npm, select it and press up button on the right side of window so many times until the line will not be higher than all ones which contain C:\Program Files\nodejs\node_modules\npm

By moving this line up, we raising priority of this path, that mean windows will earlier check this path than others (especially wrong one).

After doing this restart your terminals and try to run node-gyp as in original comment. But i have heard that it is not recomended way to do the stuff. better run commands via npx

PS. more clear guide how to change env vars

1reaction
owl-from-hogvartscommented, Apr 23, 2021

According to this https://github.com/nodejs/node-gyp/issues/2272, you should try to run npm config delete node_gyp.

My thoughts are that somewhere in configs is a line which tells to npm to use 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' path which contain excess node_modules path segment. The above line should delete wrong line from config

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module 'C:\Program Files\nodejs ... - GitHub
It's uncertain why I am getting this error after running npm cli command. Is it because nvm is pointing to that same path?...
Read more >
node.js - Error: Cannot find module 'C:\Program Files\nodejs ...
Navigate to C:\Users\%USERNAME%\AppData\Roaming\npm\node_modules and paste the copied npm directory there.
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
In my case, I got it like this "Module not found: Error: Can't resolve 'react-icons/fa' in 'C:\Users\user\Desktop\Projects\Address Locator\ ...
Read more >
Cannot find module (node.js / npm) - javascript - Super User
I run the command "node run index.js" but I keep getting met with an error saying:
Read more >
Fix Global Installs Not Working | "Cannot find module" error FIX
Getting " Cannot find module " after installing something globally (with -g)? Well, this video shows you how to fix global package/module ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found