While playing around with Flux & React I ran into some issues using a yoeman flux generator. It kept failing on “node-gyp rebuild”. If you do any development on Windows you’ve likely run into issues with node-gyp before. The core of the problem is that node-gyp is no longer being actively developed  and so it has some old dependencies that a modern development env might not have.

node-gyp rebuild failed

node-gyp rebuild failed

How to fix?

  1. Goto Control Panel -> Programs and Features and uninstall “Microsoft Visual C++2010 x64 Redistributable” and “Microsoft Visual C++ 2010 x86 Redistributable” (if present)cpluplus_redist
  2. Download and install Python 2.7.3 (if you have Python 3.x already installed, just leave it, both can coexist)
  3. Visual C++ 2010 Express or Visual Studio 2010
  4. Windows SDK 7.1
  5. Visual Studio 2010 SP1
  6. Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1

IMPORTANT: The order of steps above is important!

Now open a command window/console and enter the following commands

npm config set python /Python27/python.exe --global
npm config set msvs_version 2010 --global

Final Step

Finally goto Start -> All Programs -> Microsoft Windows SDK v7.1 -> Windows SDK 7.1 Command Prompt

sdk-cmd

From this command window the `node-gyp rebuild` command will work.

NOTE: You only need to use the Windows SDK 7.1 Command Prompt when running `npm install`, once installed can go back to normal command window.


23 Comments » for Fix ‘node-gyp rebuild’ error on windows
  1. Anton says:

    Thanks for the post, it helped me configure a react.js project to run on Windows. One note: the architecture of the installed dependencies should match the architecture of the Node.js distribution being used. At one point I got the following error:

    MSB8007: The Platform for project ‘contextify.vcxproj’ is invalid. Platform=’x64′

    This was solved when I installed an x86 version of Node.js and added its location to the PATH variable.

  2. David says:

    I managed to get node-gyp working on Win 8.1 x64 with VS2013, Node v0.12.3, and python 2.7.9. The trick was to install Microsoft Build Tools 2013 – see 08/16/2014 entry in https://github.com/brianmcd/contextify/wiki/Windows-Installation-Guide

    After installing the build tools, npm install, or npm install –msvs_version=2013, or –msvs_version=2012
    all work without the previous MSBuild errors.

    Note: I haven’t actually gotten anywhere with React and Flux, but at least I got npm install to work with the React Starter Kit from WebStorm.

    • Haiyun says:

      I can comment that this indeed works. I succeeded using windows 7 x64, Node 0.12.3, python 2.7.10, Microsoft Visual Studio Express 2013, and Microsoft Build Tools 2013. I followed steps 1, 2, and 4 and then I installed MVSE 2013 and MBT 2013 and run npm install -msvs_version=2013. This did the trick for me. Hopefully this helps for someone!

  3. Gerren says:

    Robert, thank you! I’d been looking for a solution for so long.

  4. sean says:

    Hi,
    The Visual C++ 2010 Express link takes you to a download that only has 2013 and up. Does it matter if our version of visual studio is 2015? Do you know where we can find the downloads for 2010? I have been looking everywhere. Thanks!!

  5. sean says:

    Robert, thanks so much for the tutorial. I have followed your tutorial through and still get the below error. Is there something I have missed? I could really use your help here

    C:\DEV\grid-ui>npm install
    |

    > contextify@0.1.9 install C:\DEV\grid-ui\node_modules\gulp-arialinter\node_modu
    les\arialinter\node_modules\jsdom\node_modules\contextify
    > node-gyp rebuild

    C:\DEV\grid-ui\node_modules\gulp-arialinter\node_modules\arialinter\node_modules
    \jsdom\node_modules\contextify>if not defined npm_config_node_gyp (node “C:\User
    s\x217197\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modu
    les\node-gyp\bin\node-gyp.js” rebuild ) else (rebuild)
    Traceback (most recent call last):
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\gyp_main.py”, line 18, in
    sys.exit(gyp.script_main())
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\__init__.py”, line 534, in script_main
    return main(sys.argv[1:])
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\__init__.py”, line 527, in main
    return gyp_main(args)
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\__init__.py”, line 503, in gyp_main
    options.circular_check)
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\__init__.py”, line 98, in Load
    generator.CalculateVariables(default_variables, params)
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\generator\msvs.py”, line 1867, in CalculateVariables
    generator_flags.get(‘msvs_version’, ‘auto’))
    File “C:\Users\x217197\AppData\Roaming\npm\node_modules\npm\node_modules\node-
    gyp\gyp\pylib\gyp\MSVSVersion.py”, line 402, in SelectVisualStudioVersion
    versions = _DetectVisualStudioVersions(version_map[version], ‘e’ in version)

    KeyError: ‘2015’
    gyp ERR! configure error
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack at ChildProcess.onCpExit (C:\Users\x217197\AppData\Roaming\np
    m\node_modules\npm\node_modules\node-gyp\lib\configure.js:343:16)
    gyp ERR! stack at ChildProcess.emit (events.js:98:17)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:810:
    12)
    gyp ERR! System Windows_NT 6.1.7601
    gyp ERR! command “node” “C:\\Users\\x217197\\AppData\\Roaming\\npm\\node_modules
    \\npm\\node_modules\\node-gyp\\bin\\node-gyp.js” “rebuild”
    gyp ERR! cwd C:\DEV\grid-ui\node_modules\gulp-arialinter\node_modules\arialinter
    \node_modules\jsdom\node_modules\contextify
    gyp ERR! node -v v0.10.32
    gyp ERR! node-gyp -v v1.0.3
    gyp ERR! not ok
    npm ERR! Windows_NT 6.1.7601
    npm ERR! argv “node” “C:\\Users\\x217197\\AppData\\Roaming\\npm\\node_modules\\n
    pm\\bin\\npm-cli.js” “install”
    npm ERR! node v0.10.32
    npm ERR! npm v2.7.3
    npm ERR! code ELIFECYCLE

    npm ERR! contextify@0.1.9 install: `node-gyp rebuild`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the contextify@0.1.9 install script ‘node-gyp rebuild’.
    npm ERR! This is most likely a problem with the contextify package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! node-gyp rebuild
    npm ERR! You can get their info via:
    npm ERR! npm owner ls contextify
    npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request:
    npm ERR! C:\DEV\grid-ui\npm-debug.log

    • sean says:

      one thing I noticed is my path/to/nodejs. I did set it as an envrionmental variable in my PATH to the correct path: c:/program files/nodejs and it does not seem to follow that path..

  6. David says:

    Thank you for your wizardry! Just wish this was not black magic!

  7. emiliano says:

    Hi,

    i followed all the instructions but i’m having a different problem, my sdk 7.1 command prompt can’t find npm (npm is not recognized as an internal or external command error) but the normal cmd window can. Could you please help me with this? Thanks in advance

    • Robert says:

      Make sure Node is installed in a location like C:\devapps\nodejs\ (and not like C:\Program Files\ – The space (” “) can cause issues).

      Open up the SDK console and enter: `set PATH=%PATH%;C:\devapps\nodejs\` should work then.

      • emiliano says:

        Hi Robert,

        i tried what you said but i’m still having the same issue, this is really strange since i followed this guide before and it was working fine… it all started when i installed a newer version of nodejs and then tried to go back (WHYYYYYYYYYYYY DID I DO THAT :/). Thanks a lot for your answer btw.

      • emiliano says:

        btw on environment variables i have :

        C:\Users\EmilianoNicolás\AppData\Roaming\npm on PATH for user variables and

        C:\devapps\nodejs\ on path for system variables

      • emiliano says:

        ISSUE SOLVED, i managed to solve the issue and your previous anwser was very helpful. Thanks a lot mate

  8. Agus Rizwan says:

    Mr.Robert, thanks so much for the tutorial. I have followed your tutorial all done.
    i found something error, I could really use your help here

    C:\Program Files\Microsoft SDKs\Windows\v7.1>node-gyp rebuild
    gyp info it worked if it ends with ok
    gyp info using node-gyp@3.2.1
    gyp info using node@5.2.0 | win32 | ia32
    gyp ERR! configure error
    gyp ERR! stack Error: EPERM: operation not permitted, mkdir ‘C:\Program Files\Mi
    crosoft SDKs\Windows\v7.1\build’
    gyp ERR! stack at Error (native)
    gyp ERR! System Windows_NT 6.1.7600
    gyp ERR! command “C:\\Program Files\\nodejs\\node.exe” “C:\\Users\\Agus Rizwan\\
    AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js” “rebuild”
    gyp ERR! cwd C:\Program Files\Microsoft SDKs\Windows\v7.1
    gyp ERR! node -v v5.2.0
    gyp ERR! node-gyp -v v3.2.1
    gyp ERR! not ok

    • Robert says:

      From the error, it looks like a permissions issue. Try opening with Administrator privileges, press the Start button, find the shortcut to the SDK command console, holding down the “Ctrl + Shift” key, then click on the shortcut. Then run command again.

      • Agus Rizwan says:

        Thanks Mr. Robert I have followed your advice, but same error

        Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1
        \.
        Targeting Windows 7 x86 Debug

        C:\Windows\system32>node-gyp rebuild
        gyp info it worked if it ends with ok
        gyp info using node-gyp@3.2.1
        gyp info using node@5.2.0 | win32 | ia32
        gyp info spawn c:\python27\python.EXE
        gyp info spawn args [ ‘C:\\Users\\Agus Rizwan\\AppData\\Roaming\\npm\\node_modul
        es\\node-gyp\\gyp\\gyp_main.py’,
        gyp info spawn args ‘binding.gyp’,
        gyp info spawn args ‘-f’,
        gyp info spawn args ‘msvs’,
        gyp info spawn args ‘-G’,
        gyp info spawn args ‘msvs_version=auto’,
        gyp info spawn args ‘-I’,
        gyp info spawn args ‘C:\\Windows\\system32\\build\\config.gypi’,
        gyp info spawn args ‘-I’,
        gyp info spawn args ‘C:\\Users\\Agus Rizwan\\AppData\\Roaming\\npm\\node_modul
        es\\node-gyp\\addon.gypi’,
        gyp info spawn args ‘-I’,
        gyp info spawn args ‘C:\\Users\\Agus Rizwan\\.node-gyp\\5.2.0\\include\\node\\
        common.gypi’,
        gyp info spawn args ‘-Dlibrary=shared_library’,
        gyp info spawn args ‘-Dvisibility=default’,
        gyp info spawn args ‘-Dnode_root_dir=C:\\Users\\Agus Rizwan\\.node-gyp\\5.2.0’
        ,
        gyp info spawn args ‘-Dnode_gyp_dir=C:\\Users\\Agus Rizwan\\AppData\\Roaming\\
        npm\\node_modules\\node-gyp’,
        gyp info spawn args ‘-Dnode_lib_file=node.lib’,
        gyp info spawn args ‘-Dmodule_root_dir=C:\\Windows\\system32’,
        gyp info spawn args ‘–depth=.’,
        gyp info spawn args ‘–no-parallel’,
        gyp info spawn args ‘–generator-output’,
        gyp info spawn args ‘C:\\Windows\\system32\\build’,
        gyp info spawn args ‘-Goutput_dir=.’ ]
        gyp: binding.gyp not found (cwd: C:\Windows\system32) while trying to load bindi
        ng.gyp
        gyp ERR! configure error
        gyp ERR! stack Error: `gyp` failed with exit code: 1
        gyp ERR! stack at ChildProcess.onCpExit (C:\Users\Agus Rizwan\AppData\Roamin
        g\npm\node_modules\node-gyp\lib\configure.js:305:16)
        gyp ERR! stack at emitTwo (events.js:88:13)
        gyp ERR! stack at ChildProcess.emit (events.js:173:7)
        gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_proces
        s.js:201:12)
        gyp ERR! System Windows_NT 6.1.7600
        gyp ERR! command “C:\\Program Files\\nodejs\\node.exe” “C:\\Users\\Agus Rizwan\\
        AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js” “rebuild”
        gyp ERR! cwd C:\Windows\system32
        gyp ERR! node -v v5.2.0
        gyp ERR! node-gyp -v v3.2.1
        gyp ERR! not ok

        C:\Windows\system32>

  9. vingorius says:

    Env : Windows 8.1 & git for windows.
    Install : Visual Studio Express 2015 for Windows Desktop
    Windows SDK for Windows 8.1

    then, it work. Thanks.

    • Agus Rizwan says:

      i use env: windows7
      Python 2.7.3
      Visual C++ 2010 Express or Visual Studio 2010
      Windows SDK 7.1
      Visual Studio 2010 SP1
      Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1
      Node.js V5.2.0

  10. Tony says:

    I am getting stuck with the install. Followed the above and getting this. Any ideas?

    gyp ERR! build error
    gyp ERR! stack Error: `msbuild` failed with exit code: 1
    gyp ERR! stack at ChildProcess.onExit (C:\nodejs\node_modules\npm\node_modul
    es\node-gyp\lib\build.js:270:23)
    gyp ERR! stack at emitTwo (events.js:87:13)
    gyp ERR! stack at ChildProcess.emit (events.js:172:7)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_proces
    s.js:200:12)
    gyp ERR! System Windows_NT 6.3.9600
    gyp ERR! command “C:\\nodejs\\node.exe” “C:\\nodejs\\node_modules\\npm\\node_mod
    ules\\node-gyp\\bin\\node-gyp.js” “rebuild”
    gyp ERR! cwd C:\nodejs\node_modules\contextify
    gyp ERR! node -v v4.3.0
    gyp ERR! node-gyp -v v3.0.3
    gyp ERR! not ok
    npm ERR! Windows_NT 6.3.9600
    npm ERR! argv “C:\\nodejs\\node.exe” “C:\\nodejs\\node_modules\\npm\\bin\\npm-cl
    i.js” “install” “contextify”
    npm ERR! node v4.3.0
    npm ERR! npm v2.14.12
    npm ERR! code ELIFECYCLE

    npm ERR! contextify@0.1.15 install: `node-gyp rebuild`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the contextify@0.1.15 install script ‘node-gyp rebuild’.
    npm ERR! This is most likely a problem with the contextify package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! node-gyp rebuild
    npm ERR! You can get their info via:
    npm ERR! npm owner ls contextify
    npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request:
    npm ERR! C:\nodejs\npm-debug.log

    C:\nodejs>

  11. Tony says:

    I got it installed now. I started from scratch (reverted snapshot, before any VS was installed). Followed the guide above and it worked…….

2 Pings/Trackbacks for "Fix ‘node-gyp rebuild’ error on windows"

Leave a Reply

Your email address will not be published. Required fields are marked *

*