Windows users are not happy.
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
About the registry hack, is it also not required with default installation (or will it be fixed in RTM)?
@jasonwilliams200OK it's not required with the default installation, and I don't fully understand what's up with the custom install yet. Once my hunch is verified by folks on this thread, we can start digging into that further...
@mousetraps Here is my steps, hope those will help you address the problem:
- Install VS2012 express, install windows10 sdk as the npm build prompted.
- uninstall vs2012 express and install vc2015 build tools
- uninstall windows 10 sdk and reinstall May be some of those steps corrupt the registry. I finally uninstall all of those above and reinstall the vc2015 build tools and the windows 10 sdk. I still got the warning message: “warning MSB8003: Could not find WindowsSDKDir variable from the registry"
Please offer a registry fix tool whether the problem was fixed before RTM or not. Thanks a lot.
@mousetraps,
You are right it works without registry hack.
- I created a brand new Windows 7 VM.
- Installed .NET framework 4.5.1.
- Installed Build Tools 2015 Technical Preview with Default option in Setup.
- Installed node.js (v5.1)
- Installed Python 2.7.10.
- Ran
npm config set msvs_version 2015 --globalin cmd.
=== Configuration Done ===
Then installing any native module package (such as npm install selenium-webdriver) worked fine.
Separate from this discussion
Note that at this point running %programfiles(x86)%\microsoft visual studio 14.0\vc\vcvarsall.bat without the registry hack throws: ERROR: Cannot determine the location of the VS Common Tools folder. So once i ran 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\\" in elevated command prompt, vcvarsall.bat command was successful afterwards.
I'm not sure if this belongs in this thread but its certainly Windows related.
This seems a huge problem - npm scripts everywhere set environment variables before running commands and this breaks on Windows of course because this command format is not valid.
Now that I understand the problem I am coming to realise that on Windows this breaks vast amounts of node and npm packages and in order to make just about anything work I will need to be constantly digging in to packaging source code to make things work. I wonder if anything can be done?
The problem is made even worse on Windows because Powershell and the Windows command prompt have a different syntax for setting environment variables. Ugh.
Here's an example of what I mean:
"scripts": { "test": "NODE_ENV=test mocha --compilers js:babel/register --recursive --require ./test/setup.js $(find test -name '*.spec.js')", "test-watch": "npm test -- --watch", "test-e2e:crdv": "chromedriver", "test-e2e": "NODE_ENV=test mocha --compilers js:babel/register --require ./test/setup.js --require co-mocha ./test/e2e.js", "lint": "eslint .", "hot-server": "node server.js", "build": "NODE_ENV=production webpack --config webpack.config.production.js --progress --profile --colors", "start": "electron .", "start-hot": "HOT=1 NODE_ENV=development electron .", "package": "NODE_ENV=production node package.js", "package-all": "npm run package -- --all" },
Perhaps a practical solution is for npm to detect commands that do platform-specific environment variable setting and rewrite those commands to work with Windows?
@dukedougal I know this is not a solution, but send them a PR and use https://www.npmjs.com/package/cross-env instead
@luisrudge millions of voices cry out in terror every time they get smashed with npm errors and this is a HUGE problem for Windows users. If npm / node.js are ever to coexist peacefully then this needs to be solved without users or packagers having to think about it - at least for the most common cases.
Microsoft, if it wants to reduce the massive pain of using node.js on Windows, should step up and modify npm to automatically handle transformation of unix style commands into Windows style commands.
Well.. while I like to dream of that, I doubt that this is even possible to do in in a reliable way..
@luisridge I thought this thread was meant to have the attention of some of MIcrosoft's finest minds? Surely some of them can turn their attention to fixing this issue. It doesn't seem like it should be that hard to modify a unix style command into a Windows style command and npm is the logical place to do that - in fact really the only place to do that.
I'm betting an analysis of all the package.json files in the npm repository would show vast numbers of them contain unix style environment variable setting prior to command execution. It's an import problem which MIcrosoft should fix.
@dukedougal
- Most of those don't need native code. Example: rimraf
- npm isn't the the only place to make Unix replacements. Equivalents have been made in Python and others. Also, 90% of the basic Unix utilities have been ported to Windows natively. Not to mention there's active work on a POSIX-conforming BSD derivative in pure Haskell.
- They have made work on the issue. The MSVS 2015 compiler toolchain is now independent of the IDE. Although that won't solve older environments (and it's unlikely they're going to backport the changes), they've made changes to the current version. The problem now lies in node-gyp, which when though they have worked out the bulk of the problem, there's still the problem with outdated versions being shipped with Node and outdated Node versions they still have to support.
It's not as simple to fix once you start thinking about all the details.
On Thu, Nov 26, 2015, 16:58 dukedougal [email protected] wrote:
@luisridge I thought this thread was meant to have the attention of some of MIcrosoft's finest minds? Surely some of them can turn their attention to fixing this issue. It doesn't seem like it should be that hard to modify a unix style command into a Windows style command and npm is the logical place to do that - in fact really the only place to do that.
— Reply to this email directly or view it on GitHub https://github.com/nodejs/node-gyp/issues/629#issuecomment-159997986.
@impinball in most cases it's nothing more than setting an environment variable before executing a command - that's super simple - I think you're seeing a much bigger problem than I'm describing.
In my experience, the most obnoxious thing to do cross platform is environment variables. Either use a build system which is already filled with boilerplate, or use a complicated bunch of boilerplate around your tools. It should be possible to make a wrapper script for executing programs with specific variables, but I've had some trouble making this seemingly trivial script.
And forget shell scripting. Bash and Coreutils have been ported to Windows, but you can't assume that's on a Windows machine. Not very many Windows users, even developers, have heard of Chocolatey.
The next most complicated part is dealing with native modules and supported platforms/versions. Not "can this build that", but "does this support $OS" (why I run into issues with Flow) and/or "does this support Node/iojs $VERSION" (limiting my use of jsdom). A large SDK download is inconvenient, but unless your development machine is that limited in space, it pales in comparison to this.
But yes, I would appreciate not having to download the entirety of VS just to compile some C++.
On Thu, Nov 26, 2015, 23:15 dukedougal [email protected] wrote:
@impinball https://github.com/impinball in most cases it's nothing more than setting an environment variable before executing a command - that's super simple - I think you're seeing a much bigger problem than I'm describing.
— Reply to this email directly or view it on GitHub https://github.com/nodejs/node-gyp/issues/629#issuecomment-160038590.
@dukedougal,
Unix which comes default with bash (e.g.most Linux and OSX):
{
"task": "MY_TURNKEY=42 node pathto/myscript.js # does not work on FreeBSD.chs+Windows"
}
Unix which comes default with csh (e.g.FreeBSD):
{
"task": "setenv MY_TURNKEY 42; node pathto/myscript.js # does not work on Linux+OSX+Windows"
}
Windows cmd:
{
"task": "SET MY_TURNKEY=42 && node pathto/myscript.js :: does not work on Unix or Win.PowerShell"
}
Windows PowerShell:
{
"task": "$env:MY_TURNKEY=42; node pathto/myscript.js # does not work on Unix or Win.cmd"
}
As evident, I agree that there is a disharmony in that arena, but I don't think the solution is to write a 'cross-platform environment variable transformation layer' as it is more complicated that it appears.
The benefit of environment variable is to have set it once for all the scripts being imported during the process life-cycle. To achieve that you can probably make your script accept a parameter node myscript --turnkey=42 and then on top of myscript.js, fetch the value of turnkey and set it to process.env.MY_TURNKEY then rely on process.env.MY_TURNKEY everywhere. This will let you avoid parsing the command-line argument in every imported file by myscript.js.
@jasonwilliams200OK good analysis of the problem.
All I'm saying is that without a fix for this, large numbers of packages fail on Windows.
If a solution can be found that automatically solves it for all packages then life will be much easier on Windows.
Sure, I could solve it myself but that means every single time into the future I need to install a package on Windows that uses environment variables in bash/Linux form (and most of them do) then I'll need to cast whatever spell is required. Many, many other users on Windows won't have the ability or the interest to fix it - I certainly don't have the interest to fix it, especially not over and over.
As I said earlier, if MIcrosoft want node.js and npm to work without deep pain for the user base, this needs to be addressed.
As an example, Babel has an env object for conditional plugin inclusion
that sucks if you're not using a complex build system and it has to build
on multiple platforms (e.g. you're using npm scripts). Otherwise, it's a
powerful tool.
On Fri, Nov 27, 2015, 02:50 dukedougal [email protected] wrote:
@jasonwilliams200OK https://github.com/jasonwilliams200OK good analysis of the problem.
All I'm saying is that without a fix for this, large numbers of packages fail on Windows.
If a solution can be found that automatically solves it for all packages then life will be much easier on Windows.
Sure, I could solve it myself but that means every single time into the future I need to install a package on Windows that uses environment variables in bash/Linux form (and most of them do) then I'll need to cast whatever spell is required. Many, many other users on Windows won't have the ability or the interest to fix it - I certainly don't have the interest to fix it, especially not over and over.
As I said earlier, if MIcrosoft want node.js and npm to work without deep pain for the user base, this needs to be addressed.
— Reply to this email directly or view it on GitHub https://github.com/nodejs/node-gyp/issues/629#issuecomment-160061739.
As of this morning (2015-12-02), the download link for the Build Tools (https://www.microsoft.com/en-us/download/details.aspx?id=49512) appear to be broken. Found them at https://www.microsoft.com/en-us/download/details.aspx?id=49983
@jbblanchet et al - The "evergreen" link from now on for the latest Visual C++ Build Tools 2015 installer should be http://go.microsoft.com/fwlink/?LinkId=691132 . We're working on fixing any references to the download.microsoft.com website because those links are not available long-term. If you know of any other places that reference these old links, please let me know. Thanks!
@mluparu, as someone mentioned on VS blog in comments: http://blogs.msdn.com/b/visualstudio/archive/2015/11/30/visual-studio-update-1-rtm.aspx.
you guys announce a technical preview of Built Tools for C++ few weeks ago: www.microsoft.com/.../details.aspx. I can't find Update 1's counter part anywhere on www.visualstudio.com/downloads, not even under 'Tools for Visual Studio 2015'. The
Build Toolsunder that title is for C# not C++.. Please make it available. On this note, can you guys differentiate the names, so people don't confuse 'Build Tools 2015' and 'Build Tools 2015 for C++'..
Please rename the Build Tools 2015 for C++ to something like VC Runtime 2015 and make it available at http://www.visualstudio.com/downloads under Tools for Visual Studio 2015 section to make it easily discoverable.
Thanks for the suggestion. The official name is "Visual C++ Build Tools 2015" and while I understand the confusion it might create, there is little wiggle room here in branding.
This package will definitely show up on http://visualstudio.com/downloads when it RTMs, hopefully reducing that confusion even further, but for now, while it is still in technical preview, most of the announcements will be done through blogposts and forums.
@mluparu can this also be made available via powershell package management? It'd be pretty nice to be able to do install-package vcppbuildtools2015 (or whatever) and get it onto the system.
@factormystic I second that idea. Much easier to set up new Windows dev machines that way.