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

Created on 8 Dec 2018  路  15Comments  路  Source: nodejs/node-gyp

  • 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
+ [email protected]
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?

Most helpful comment

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.

All 15 comments

Note that the module that the script is trying to resolve is:

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

which doesn't exists, unlike:

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

which exists. Furthermore, node 'C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js' runs node-gyp as expected and everything works. Perhaps there is a way to specify that the command node-gyp should run this?

I'm experiencing the same issue.

node v8.11.1
npm 5.6.0

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.

I'm having a similar issue, but with configuring node-gyp. I have Nodejs version 11.3.0 and NPM version 6.3.0. The output from node-gyp is on this Gist: https://gist.github.com/DragonOsman/ccac1f3033635d6b8470e8b9541de62f .

I tried node-gyp configure --msvs_version=2017 after doing npm config set python C:\Python27\python.exe and npm config set msvs_version=2017.

@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.

@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

I set that environment variable, but I still have the same error messages.

By the way, I also have another issue thread open for my problem: https://github.com/nodejs/node-gyp/issues/1629

@DragonOsman you're having a different problem, but try this instead: npm config set python "C:\Python27\python.exe". Note the " characters. It can't seem to find a path I think it might be Python.

Without the quotes the result of npm config list looks like this:

python = "C:Python27python.exe"

With quotes it looks like this:

python = "C:\\Python27\\python.exe"

If this doesn't fix the problem, double check all your paths which were giving as input if they are valid. See if adding quotes help, etc.

I still have that problem, and I've already done what I think I could've in my PATH variable. And I also don't know why it keeps using VS2015 (msvs_version=2015) when I set it to be 2017 already.

Edit: And yeah, all of the paths used as input seem to be fine.

Be sure to configure your globally installed node-gyp instead of the one npm comes with. You'd might mixing up two versions.

If I recall correctly, the default one being executed is the one which comes with npm. Seeing your log makes me think you're trying to run a globally installed one.

How do I make sure I'm using the globally installed one? And I installed it using the command npm install -g node-gyp, IIRC.

Edit: I also cloned this repository just in case. Do I have to build it now, or can I just start using it?

Actually, I think it's already using the globally installed one. In the nodejs/node_modules/npm/node_modules/node-gyp/bin directory. The problem seems to be something else. And like I said before, the paths it's using as input seem to be fine. I checked.

Can you provide the output with the --verbose flag used?

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

Node.js versions < 10 are no longer supported. https://github.com/nodejs/Release#readme

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lopezdp picture lopezdp  路  3Comments

swaj picture swaj  路  3Comments

jlchereau picture jlchereau  路  3Comments

halkar picture halkar  路  4Comments

kimown picture kimown  路  3Comments