node-gyp: Cannot find module 'C:\...\node-gyp\bin\node-gyp.js'
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (9 by maintainers)
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 excessnode_modules
path segment. The above line should delete wrong line from configWhat forked in my case was, removing the path
Then reinstalling the package no need to change the version of npm or node.
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 runnode-gyp
it has executed node-gyp from internals of npm and because npm uses magicalnode-gyp.cmd
to launch the node-gyp itself, you got such strange error.The solution is:
Win
+R
SystemPropertiesAdvanced.exe
and pressEnter
Environment Variables
button in bottom right corener of the windowPath
var in User variables area and pressEdit
appdata\roamning\npm
, select it and pressup
button on the right side of window so many times until the line will not be higher than all ones which containC:\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 vianpx
PS. more clear guide how to change env vars