node-gyp icon indicating copy to clipboard operation
node-gyp copied to clipboard

Windows users are not happy.

Open luisrudge opened this issue 11 years ago • 474 comments

It all started with this conversation.

As I said, I'm pretty much a newbie and I don't even know what node-gyp does, but what I DO know is that it's a pain to run Windows and install a project with node-gyp as a dependency. Some numbers:

It's bizarre that a nodejs developer needs to install visual studio (even the express edition) in order to be able to work on Windows. Even more bizarre is that I, as a .NET developer with full visual studio installed in my machine still can't download a bunch of projects that use this project.

With that being said, I'd like to know from all of you what should we do to make windows users fall in the pit of success? What are the alternatives? Does Microsoft can solve this in any way?

This issue is fixed (kinda)

@mousetraps pointed that Microsoft is shipping the C++ build tools separately now. Check here

Some updates on this gigantic thread

Absolutely non-official statement that @Microsoft is aware of this issue and seeing what can be done

@mousetraps said that this thread "is high on people's radar" at @Microsoft

Very good Q&A about noge-gyp issues on Windows and why they happen

@dekarguy took the time to answer some questions about what we all are going through

luisrudge avatar May 22 '15 03:05 luisrudge

I agree with that :) Somewhere, somehow, we need better docs for this kinds of errors.

luisrudge avatar Nov 18 '15 14:11 luisrudge

Using the standalone C++ build tools I can't get socket.io to build it keeps throwing this error:

$ npm install --save socket.io
npm WARN package.json @ No repository field.
npm WARN package.json @ No license field.

> [email protected] install D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild

\
D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate>if not defined npm_config_node_gyp (node "D:\installs\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version  number. [D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build\validation.vcxproj]
  validation.cc
c:\users\mtpultz\.node-gyp\4.2.2\include\node\uv-win.h(32): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory [D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules \utf-8-validate\build\validation.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\installs\nodejs\node_modules\npm\node_modules\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_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command "D:\\installs\\nodejs\\node.exe" "D:\\installs\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v4.2.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

> [email protected] install D:\projects\nodejs\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild

Any suggestions?

mtpultz avatar Nov 19 '15 00:11 mtpultz

These kinds of errors are exactly what I'm talking about.

Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version  number.

There is the error. Hint: look for warning: or error:. Often times errors are accompanied by warnings that tell you what's really wrong.

Install the Windows SDK, or re-install MSVS.

Qix- avatar Nov 19 '15 01:11 Qix-

@Qix- Why do I have to install MSVC when they just provided the C++ build tools and I have them installed with Python 2.7 and followed the instructions provided by @mousetraps, which seemed to work for some people, but maybe they weren't running Windows 10. I just want to compile not use their IDE or even go near .NET programming, which I know absolutely nothing about. I tried your other suggestion and downloaded and ran the Windows SDK and it said I was up to date already.

The solution I'm using now is just attaching the project to a virtualbox like Homestead in my case as I'm using Laravel + Redis + ExpressJS in this application, then just SSH in and run npm. Way less hassle then buggering around for hours downloading/installing/uninstalling/downloading/reinstalling/etc.

mtpultz avatar Nov 19 '15 07:11 mtpultz

Sorry, should have read "MSVS" (MS Visual Studio). I haven't (yet) installed the independent build tools by Microsoft yet, but I wouldn't be surprised if they didn't include the SDK. Plus, seeing as how Windows 10 is fairly new I wouldn't be surprised if there was some other obscure error.

Did you download/install the Windows SDK? @mousetraps do the build tools include the windows SDK?

Qix- avatar Nov 19 '15 07:11 Qix-

@mtpultz, we have a solution to the exact problem by @ricmed205 above:

I finally got it working checking BOTH windows 10 SDKs and windows 8 SDK (I'm on win10) when installing the 2015 build tools. It seems that somehow the windows 10 SDKs is built on top of the windows 8 SDKs OR the windows 10 SDKs package has a bug that fails to add the correspondent registry values, and my system is simple using the windows 8 SDKs (when I added it later).

As @mousetraps mentioned that SDKs are included, here is the blog post http://blogs.msdn.com/b/vcblog/archive/2015/11/02/announcing-visual-c-build-tools-2015-standalone-c-tools-for-build-environments.aspx which details on what is included and what is marked optional etc.

ghost avatar Nov 19 '15 07:11 ghost

if you rerun the build tools setup and select both 8,1 and 10 SDKs, it will install the missing one.

ghost avatar Nov 19 '15 07:11 ghost

Thanks @jasonwilliams200OK that did it.

mtpultz avatar Nov 19 '15 08:11 mtpultz

@jasonwilliams200OK As mousetraps pointed here, latest nodejs is not needed (v0.x, v4, v5 works). I work with v4 myself.

@luisrudge I would add the following remarks in the fix summary:

  • A warning that the 2015 Build Tools is in fact a several gb install (and as for now, there is no other way).
    • For windows 10: check both windows 8 AND windows 10 SDK options (this can blindside you like with me/mtpultz).

Honestly, what really prevented/frightened me from using a node-gyp dependent module (after days frustrated with why I couldn't install selenium-webdriver, just as any other module, and researching/learning then what node-gyp was) was the size of the MSVS/Build Tools install. Why on earth would I need several GBs of code to work with at most MB size programs (JS scripts, nodejs, python, npm modules...). "Is python needed to work with sockets.io module? Mmm Ok, I'm not quite sure why this is the case, but, let's see: download/install~30MB? easy, let's do it. Next, download/install a Gbs thing. What?? I must be doing something wrong or there SHOULD be a better way somewhere else. Hell, photoshop/dreamweaver are ~1GB and the whole windows OS is ~15GB..."

Can someone explain why all those GBs are needed? Also, I see in the Build Tools: 800 MB of available hard disk space, but I got installed ~4.5Gbs? which I went an entire day downloading.

Sorry for the rant. Hopefully, the Q&A will supplement the docs to quickly/better explain the newbies like me and be more confident about the whole nodejs/windows experience.

rickmed avatar Nov 19 '15 17:11 rickmed

So here it is. I have tested these steps multiple times on (each time) newly created Windows 7 SP1 VMs with IE8.

Scenario: I have a brand new Windows system, what to do?

  • [Only if it is Windows 7 then and you don't already] Download .NET Framework 4.5.1 and run the installer.
  • Download Build Tools 2015, run the installer, select Custom, click Next and check both SDKs, click Next and then Install.
  • Download and install latest node.js.
  • Download and install Python 2.7.x.
  • Open cmd and run npm config set msvs_version 2015 --global.

Hopefully it is a temporary registry fix and they will fix it before Build Tools get out of Technical Preview status. Out of 4 times it created that registry value once.

  • Start > Run > cmd (and press Ctrl+Shift+Enter to Run as Administrator):

    For 64-bit Windows

    :: copy paste this command and press enter
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7 /v 14.0 /t REG_EXPAND_SZ /d ^%programfiles(x86)^%"\Microsoft Visual Studio 14.0\\"
    

    For 32-bit Windows

    :: copy paste this command and press enter
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7 /v 14.0 /t REG_EXPAND_SZ /d ^%programfiles^%"\Microsoft Visual Studio 14.0\\"
    

Now install the package like npm install selenium-webdriver and it should work!

My installation is not brand new, I had some related stuff installed and now I am getting MSB4019 or MSB8020.

This means somehow you have incorrect version of msbuild in PATH. To fix that, put C:\Program Files (x86)\MSBuild\14.0\Bin; at the beginning of PATH under System Environment Variables. To do it quickly (without making permanent change), run SET PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin;%PATH% in command prompt in case of 64-bit Windows or %ProgramFiles%\MSBuild\14.0\Bin; in case of 32-bit Windows. Then run your intended npm install command.

Finally, what to expect?

Expect every package which requires C/C++ code compilation at the time of installation to succeed on Windows, exactly as they compile at installation time on Unix-like operating systems, except those which are not supporting Windows at all (yet?) such as node-gd. For such packages, you can find their repository URL on package's http://npmjs.org/ page and find the Windows support status in their issue tracker.


@ricmed205, I know the latest version of node.js is not a requirement here, but if you are to install right now, fetch the latest instead of some old one. Otherwise it should work on all supported (by package) versions of node.js (and conversely v8 and whatnot).

ghost avatar Nov 19 '15 19:11 ghost

@jasonwilliams200OK

Hopefully it is a temporary registry fix

Perhaps even a default .reg file for the C: drive would be useful instead of having people mess with their registries? Just a thought. Good writeup, though!

Qix- avatar Nov 19 '15 21:11 Qix-

Should there be an optional way to distribute native modules that don't involve a prebuild script? And any sane module will state what it depends on, if it isn't preinstalled. Most native modules do that already.

dead-claudia avatar Nov 20 '15 07:11 dead-claudia

Highly frustrating stuff. node-gyp is unable to find the header files from cpp.

rishantagarwal avatar Nov 20 '15 12:11 rishantagarwal

@rishantagarwal you'll be hard-pressed to find a build system that can do that reliably and efficiently. That's not node-gyp's fault.

Qix- avatar Nov 20 '15 13:11 Qix-

@jasonwilliams200OK ,

I think

Open cmd and run npm config msvs_version 2015 --global.

should actually be

Open cmd and run npm config set msvs_version 2015 --global.

teobugslayer avatar Nov 20 '15 14:11 teobugslayer

@teobugslayer, you are right, fixed above.

ghost avatar Nov 20 '15 14:11 ghost

@jasonwilliams200OK did you try a REG_EXPAND_SZ registry key type w/ %programfiles(x86)%? That could allow skipping the explanation about c:. Also instead of manually doing it with regedit, this instruction could probably be restated with a 1 line reg command.

factormystic avatar Nov 20 '15 15:11 factormystic

@fredericosilva, good idea, updated.

ghost avatar Nov 20 '15 15:11 ghost

4 days trying only to do a npm install. Download more than 6gb. Thank you Windows and everything else for this waste of time,

Yet with these errors

lehno avatar Nov 20 '15 21:11 lehno