node-gyp: node-gyp doesn't work, even when following the guidelines

  • Node Version: node v11.0.0, npm v6.4.1

  • Platform: OS Name: Microsoft Windows 10 Home OS Version: 10.0.17134 N/A Build 17134 System Type: x64-based PC

  • Compiler: ‘msbuild’ is not recognized as an internal or external command, operable program or batch file. ‘cl’ is not recognized as an internal or external command, operable program or batch file.

  • Module: node-gyp

Verbose output (from npm or node-gyp):
PS > npm install --global --production windows-build-tools
PS > npm config set python C:/Python27/python.exe
PS > npm install -g node-gyp
C:\Users\ninof\AppData\Roaming\npm\node-gyp -> C:\Users\ninof\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js
+ node-gyp@3.8.0
updated 1 package in 3.695s
PS > node-gyp

C:\Users\ninof>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"  )  else (node ""  )
internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)

According to the windows installation instructions, this should work. However, there seems to be some missing files. What can I do?

About this issue

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

Most upvoted comments

I am also experiencing the same issue and it is incredibly frustrating. The node-gyp package has been incredibly turbulent for us poor Windows users over the last few years.

@aal89 Indeed by setting the npm_config_node_gyp environment variable the node-gyp command now works!

set npm_config_node_gyp=C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js

@ninofiliu Yes there is. Try setting the environment variable npm_config_node_gyp with the correct path. (e.g. C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js).

I believe this is happening for all Windows machines because the node-gyp.cmd file is missing a ..\ in its path.

if not defined npm_config_node_gyp (
  node "%~dp0\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
) else (
  node "%npm_config_node_gyp%" %*
)

Should be (?)

if not defined npm_config_node_gyp (
  node "%~dp0\..\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
) else (
  node "%npm_config_node_gyp%" %*
)

or just set the environment variable.

I’m experiencing the same issue.

node v8.11.1 npm 5.6.0

Configuration: window 10, 64 bit, node v8.13.0, npm v6.4.1

Follow the below steps :

  1. Restart the system

  2. Open cmd by administrator

  3. Delete C:\Users\user_name.node-gyp

  4. Delete %AppData%/npm

  5. Delete %AppData%/npm-cache

  6. Check out node-gyp package

  7. npm install -g node-gyp

  8. npm install --global --production windows-build-tools

  9. node-gyp configure --python C:\Users\pcq158.windows-build-tools\python27\python.exe

  10. npm config set msvs_version 2017 --global

  11. npm install