node-gyp: Cannot find module `...\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js`

  • Node Version: v8.11.2 (node), v6.1.0 (npm)
  • Platform: Windows 10 x64
  • Compiler: ?
  • Module: -
Verbose output (from npm or node-gyp):
(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

(base) C:\Users\vertangelx\Desktop\cosmic>npm uninstall -g node-gyp
removed 105 packages in 0.848s

(base) C:\Users\vertangelx\Desktop\cosmic>npm install -g node-gyp
C:\Users\vertangelx\AppData\Roaming\npm\node-gyp -> C:\Users\vertangelx\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js
+ node-gyp@3.7.0
added 105 packages from 66 contributors in 2.02s

(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Why does running the command node-gyp tries to look for the binary in such a strange location with repeating node_modules\npm\?

C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js

Tried uninstalling and reinstalling node-gyp but error remains.

Installed node-gyp using

npm install --global --production windows-build-tools
npm install -g node-gyp

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 19 (2 by maintainers)

Most upvoted comments

For me it threw an error like below : Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' If you also can see this line in your error stack, it seems like a packaging error. What I have done is :

  1. Found that the node_gyp is actually a level up in the directory structure
  2. Opened “C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\node-gyp.cmd” in an editor
  3. removed that extra "\node_modules’ from 2nd line to read as ‘node “%~dp0....\node-gyp\bin\node-gyp.js” %*’
  4. Tested with ‘node-gyp --help’ in command prompt And it worked !

@bnoordhuis After uninstalling node, C:\Users\vertangelx\AppData\Roaming\npm directory was not deleted. Gone ahead to delete the folder, then installed Node again.

Now when I run node-gyp in the command prompt, it seems that node-gyp is not installed.

Ran npm install -g node-gyp and everything works now! Thanks!

Actually, I found the simplest solution is to create an extra \node_modules folder and copy the existing node-gyp folder into it. Then your c: drive will contain this: C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js’

You end up with a duplicate node-gyp folder, but at least this will prevent the error message when you run “node-gyp configure”. The rest of your build will not be affected by this strategy.

For those still experiencing this issue, I did this:

Uninstall everything npm. Go to /usr/local/lib/ and remove the node_modules folder completely. Make sure you have no npm or .npm folders. Next, download and install the latest node and npm from https://nodejs.org/en/. Then run npm install node-gyp -g.

This fixed it for me.