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

Jason: no, I'm using Windows (long story), but still I get the chicken pox anytime I touch any of their "development tools"... I would have been OK with a few GBs of this garbage that I can just ditch the moment my pull req. gets approved - but having to wait hours to just get another myriad of error messages is not even half funny, and even would not be half funny with the Benny Hills theme looped all the way.

ppeterka avatar Oct 24 '15 16:10 ppeterka

First - if you have vs2015 but did a "typical" install (which does not install c++ stuff), you can install the c++ stuff by going File > New Project and trying to start a c++ project. You will get options to install things. Make sure you have a couple gb on your hard disk.

Second - I think there's lots of confusion overall. Can someone involved with node-gyp write up a blog post summarizing what the problem actually is? Things I'd like to see addressed

  • What exactly is the service that node-gyp provides that sooo many projects depend on?
  • Why on earth is a c++ compiler even necessary? Hardly anything else on windows requires a c++ compiler after all.
  • Why can't we just download a compiler as part of node on windows? Or as part of the first node-gyp install?
  • What's the deal with the various configurations (an env variable and an npm variable? why?)
  • How is it that there is such a large range of things that might go wrong? It would seem like there would be just two or three things but there seems to be endless combinations.
  • What does any of this have to do with Python? What is python even being used for?
  • Why is it a version of Python that was superseded over seven years ago?
  • What about all this is easier on a *nix system than on Windows?

I'm largely a javascript and .net developer. I've had some experience with a half dozen other languages including Erlang, Ruby, Java, and others, but never anything serious with Python or C++ which is why this entire conversation is a mystery to me. In fact, any time I try to do anything on linux I generally start hitting c++ dependency walls.

I'd really like to understand the underlying issues that are causing problems on Windows. I think we could bring a lot more brainpower to this if the issues were more clear.

togakangaroo avatar Oct 26 '15 03:10 togakangaroo

@togakangaroo

I agree that a blog post detailing the issues at hand could be useful, but a little bit of research can answer all of your questions.

What exactly is the service that node-gyp provides that sooo many projects depend on?

It provides the ability to pull in natively compiled modules in to be accessible to Node.js. I.e. build C++ projects so you can use them in js.

Why on earth is a c++ compiler even necessary? Hardly anything else on windows requires a c++ compiler after all.

Because it is building native code, i.e. C++, which is super easy to do on non-Windows platforms with gcc or clang.

Why can't we just download a compiler as part of node on windows? Or as part of the first node-gyp install?

Just downloading a stand-alone compiler is one of the things that the multiple Microsoft employee posts in this thread have talked about, it is not easy to do, and less easy since they have removed the basic compiler from the latest versions of the Windows SDK.

What's the deal with the various configurations (an env variable and an npm variable? why?)

Because building c++ outside of a sandbox has many, many configurations and relies on envars that can drastically affect what is build.

How is it that there is such a large range of things that might go wrong? It would seem like there would be just two or three things but there seems to be endless combinations.

Welcome to compiling native code on a complex platform.

What does any of this have to do with Python? What is python even being used for?

Python is used internally by GYP, the CMake-like build system that node-gyp wraps and makes easier to use for node.

Why is it a version of Python that was superseded over seven years ago?

The reason python2 is required is because GYP requires it and hasn't converted to using python3. It isn't a simple switch to take a large project that many other projects depend on and change from Python 2 to 3, and so far, it doesn't seem like a large effort has been made to make that change, considering it is a low priority defect since 2009, https://code.google.com/p/gyp/issues/detail?id=36

*What about all this is easier on a nix system than on Windows?

*nix systems are a lot less complicated, you can very easily pull all your requirements (like gcc, python2, platform specific SDKS) and build and go, but on Windows, the ecosystem is a lot different, and it just isn't that simple, though many efforts, npm included, have tried to help this a ton, but there is still a lot of legacy work out there, and not enough time, money, and resources to turn it on overnight

dekarguy avatar Oct 26 '15 03:10 dekarguy

Damn @dekarguy. That's a great explanation! I'll link this in the original question. THAAAAAAANKS :)

luisrudge avatar Oct 26 '15 03:10 luisrudge

Why on earth is a c++ compiler even necessary?

For distribution, it is developer's choice whether they require end terminal to have C/C++ compilers available. For example in node-sass, we prebuild binaries and serve them from GitHub release assets. That is a too much work for repo maintainers; as for every module version (which roughly changes with every major version of node and used to change with every minor version before), there needs to be a different binary. This requirement is imposed by node.js runtime and there exist proposals to make the overall situation better (https://github.com/nodejs/node-gyp/issues/629#issuecomment-105072235).

Then we have different architectures and OSes. So the equation looks like <number of OSes to support> x <number of architectures to support> x <number of module versions to support>. There exist solutions like node-pre-gyp to automate this process. However, in node-sass we use a custom recipe to leverage AppVeyor CI to build binaries for Windows and store them as build artifacts. Hence as package devs, we don't even need a windows machine, we just download all combinations of windows binaries from AppVeyor once the release build succeeds. :)

Moreover, we backup our binaries in a separate repo: https://github.com/sass/node-sass-binaries. So we have 14 binaries for Windows, 14 for Linux, 14 FreeBSD and 7 (universal binaries) for OS X per release. And we will incorporate ARM at some point (and there is a news that MIPS is regaining popularity?). Anyhow, as a fallback (if the binary is not compatible for some astoundingly evil reason), then we do require C[++] compilers on end terminal.

Unless we have some kind of de facto solution/service for building and serving binaries (supporting BSDs and Solaris etc. obscure OSes and multi-architectures including ARM too), every npm package maintainer with native modules would either:

  • virtually create their own mini package manger to host the binaries

or

  • simply mark C[++] compilers as prerequisite to install their package (and do sometime more productive with their time). :smile:

am11 avatar Oct 26 '15 06:10 am11

It could be offtopic but... I had the problem because I had two instances of npm installed. Command where npm returned two different directorties. So I removed the topmost and ran npm i -g node-gyp or for example npm i -g browser-sync.

jackinf avatar Nov 01 '15 16:11 jackinf

@am11 so what I don't understand is - that unlike linux, I cannot think of a single piece of windows software outside of node that requires compiling from source. This includes many open source cross-platform pieces of software. This includes packages that I myself maintain over nuget. I understand that those authors simply offer a pre-built executable but there isn't this matrix problem that you describe. There's at most 2 versions x86 and x64 and the former usually works fine.

So why is it that node and specifically node package maintainers insist on compiling from source? As you say, node-sass seems to do this. What is it about node that requires re-compilation with every single node version bump? How is this unlike nearly every other piece of windows programming?

togakangaroo avatar Nov 02 '15 14:11 togakangaroo

@bgSosh forgive my C-ignorance. so does that bascially mean that the interop happens within the c program itself and not by just shelling out to an exe?

If that's the case, then in theory this would be easily solved by having anything that could possibly be accomplished by shelling out to an executable (node-sass is a great example) do so, right?

I'm just trying to understand. If the latter is true then there might be a class of dependencies that could potentially have node-gyp removed as a sub-dependency/

togakangaroo avatar Nov 02 '15 14:11 togakangaroo

@togakangaroo - I deleted my answer just after I posted it, as I'm far from an expert myself in this, and thought it would be better answered by someone more knowledgeable.

srlowe avatar Nov 02 '15 15:11 srlowe

@togakangaroo, the recompilation is required on all OSes. When the module version (which we can get from NODE_MODULE_VERSION in C or node -p process.version.modules in CLI) changes, it signifies the breaking change and loses the binary compatibility with the pervious version. I do not know exactly what needs to be done in order to bring about version to version binary compatibility but with foreign function interface (FFI) or stable ABI contract with v8, it seems like the situation may get better.

To this mix, v8 version changes (which I think is the main source of this breakage) also influence compatibility across node.js runtime versions. This disparity is abstracted away with nan for native module devs (so devs do not have to keep adding #ifdefs in their code for each function signatures etc. change; when v8 guys decide to refactor some public interface).

Some information about this behaviour can be found in node.js docs: https://github.com/nodejs/node/blob/6fff47f/doc/releases.md#4-update-srcnode_versionh.

Folks over at node.js and libuv IRC channels and @kkoopa (who have done tremendous work on nan to keep us going) helped me understand all this, once upon a time. :)

am11 avatar Nov 02 '15 17:11 am11

Hey all, in case you missed it... :smiley:

Visual C++ Build Tools 2015 (Pre-release). If you want to build your C++ projects targeting Windows desktop without having Visual Studio installed on your computer, Microsoft Visual C++ Build Tools 2015 provides the required tools: C++ compilers, libraries, build scripts, Windows SDKs. This Community Technology Preview ships with the same C++ compilers and libraries packaged with Visual Studio 2015 Update 1 RC (2015.1). http://blogs.msdn.com/b/vcblog/archive/2015/10/29/visual-studio-2015-update-1-rc-available.aspx

The config steps with Node.js should now be as follows:

  1. Install VC++ Build Tools Technical Preview, choose Custom Install, and select both Windows 8.1 and Windows 10 SDKs.

    :bulb: [Windows 7 only] requires .NET Framework 4.5.1

  2. Install Python 2.7, and add it to your PATH, npm config set python python2.7

  3. Launch cmd, npm config set msvs_version 2015 --global (this is instead of npm install [package name] --msvs_version=2015 every time.)

  4. SO MUCH npm install :tada:

So please give it a spin and send feedback if you're still running into issues or you think any crucial bits are missing. Much thanks to the VC team for pulling this off!! :smiley: +@mluparu

I've tested it with Node.js and many of the most popular / representative packages. This includes the following packages, as suggested by @am11.

  • bson
  • bufferutil
  • kerberos
  • node-sass
  • sqlite3
  • phantomjs
  • utf-8-validate

Note that there are still many other things that can go wrong when dealing with native modules - e.g. platform and compiler differences, incompatibilities with architecture, Node version, missing prerequisites (and unfortunately most packages don't provide the best indication of how and where to get those prereqs). One tool that's very helpful in debugging missing prerequisites on Windows is Dependency Walker.

BTW I'll be in SF next week giving a talk on Node.js + Windows, so definitely swing by if you're in the area, and want to chat further: https://www.eventbrite.com/e/nodejs-and-npm-for-the-windows-developer-tickets-19280683042

mousetraps avatar Nov 02 '15 23:11 mousetraps

@mousetraps Is it working on both node.js branches - 0.xx.x and 4.x.x? Which npm versions are tested?

Sogl avatar Nov 03 '15 00:11 Sogl

Thank for the update @mousetraps! This is really an excellent news. I actually skimmed through that blog post, but somehow skipped the last bit. :smile: With VS2015 Update 1 RTM, I hope we will get an ISO for offline installation which we would be able to consume with Windows Nano Server and docker containers etc. :) Currently, from the link you provided, when I downloaded VisualCppBuildTools_Full.exe and ran VisualCppBuildTools_Full.exe /layout (with the download-only switch) from cmd, first it complained the default save path has invalid ++ characters, so I changed it to c:\temp\blah, then it downloaded 1.38 GBs; which is large but comparatively much better than the VS installation.

@Sogl, per my understanding, if it compiles the package under question with one version of node.js, it should compile with all the versions that the package supports (the package maintainers need to keep their native binding up-to-date by depending on latest versions of node-gyp and nan, which sometimes takes code changes rather than mere version update).

am11 avatar Nov 03 '15 01:11 am11

@fuczak i can't install it at-all.. even without the VS2015 installed. Launcher just shows the splash-screen and then dies.. sometimes Win10 wants to investigate the issue but then recommends to close the installer

spawn-guy avatar Nov 04 '15 15:11 spawn-guy

@spawn-guy can you send the install logs? Run vscollect.exe from http://aka.ms/vscollect and share the %TEMP%\vslogs.zip, sharing it on OneDrive preferred.

Thanks!

paulvanbrenk avatar Nov 04 '15 18:11 paulvanbrenk

then it downloaded 1.38 GBs; which is large but comparatively much better than the VS installation.

OMG. It would be better to give us a link to iso-image. Not all of us have a good Internet connection.

@mousetraps Thank you very much! All works fine with node 4. My env:

Windows 7 x64
node 4.2.2
npm 3.3.12

Just tested with browser-sync and node-sass.

Sogl avatar Nov 05 '15 06:11 Sogl

@mousetraps, It's working, thank you.

coldwinds avatar Nov 05 '15 07:11 coldwinds

@mousetraps Works like a charm! Thanks you very much.

I spent hours to figure out this problem and I'm sure you saved me many hours of investigation.

My env:

Windows 7 x64
node 5.0.0
npm 3.3.6

Tested with npm install:

serialport
phantomjs
browser-sync
node-sass

darekdesu avatar Nov 05 '15 22:11 darekdesu

My experience of trying to use node.js on Windows 10, after following all the directions I can including those in this thread, is just a pounding, unrelenting hailstorm of errors.

I have given up for now.

If Microsoft wants node.js to be part of its ecosystem it's going to need to do far reaching and comprehensive QA and simulate typical user scenarios.

Right now node.js on Windows is just a huge time waste. node.js on Windows game over until someone fixes alot of stuff.

error logs here:

https://gist.github.com/dukedougal/9a2ff8a469407db6d79d

dukedougal avatar Nov 06 '15 01:11 dukedougal

@dukedougal in this case, I'd expect the same issue to occur on any platform. In particular, you're trying to install [email protected], which is incompatible with your current version of Node.js. You can tell because the errors involve syntax errors related to nan and the like. The most recent version of node-sass (currently 3.4.1) should work fine with the latest releases of Node.js.

mousetraps avatar Nov 06 '15 18:11 mousetraps