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
I did a clean format of Windows 10, installed Python 2.7.10 and the newly released nodejs v4.0.0 and everything seems like it works. node-gyp is finally working too.
I still can't install socket.io but it looks like some dependencies haven't been updated yet.
PS. Without Visual Studio.
Maybe that has to do with the new bundling of node-gyp into node 4.0.0?
"node-gyp: This release bundles an updated version of node-gyp that works with all versions of Node.js and io.js including nightly and release candidate builds. From io.js v3 and Node.js v4 onward, it will only download a headers tarball when building addons rather than the entire source."
Haven't tried it yet myself.
Sorry to see all this frustration with using node-gyp on Windows :unamused:
While it might take some time to implement, we are pursuing a solution that will eliminate the need to have VS installed when installing native modules: https://github.com/nodejs/build/issues/151
awesome @orangemocha. I'm glad someone is looking at this!
I just want to say... this is hell. I've installed several things trying to fix it, about to roll back to a safer system restore to try some more things. But seriously....
OK, so here's how I fixed my issue and got node-gyp building with Visual Studio 2015 installed.
- Be on version 0.12.2. This breaks completely on 4.0. However, v0.12.2 is what the the Visual Studio 2015 installer will install if you ask it to install Node.js.
- Make sure the C++ components of Visual Studio 2015 are installed. If you're not sure, run the installer and check.
- Update NPM using npm-windows-update.
That got it working for me, I'm able to sucessfully build sockiet.io.
@Pharylon Lucky you. npm-windows-update just hosed my system: https://github.com/felixrieseberg/npm-windows-upgrade/issues/34
Since upgrading to node4 with node-gyp v3.0.3 I'm having even more issues than before. Packages that previously installed ok are now failing. Really sick of this TBH.
@bgSosh same for me! now trying to figure out how to go back.
Just shoot me!
The x64 compilers are not currently installed.
Please go to Add/Remove Programs to update your installation.
Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.0.
Targeting Windows 7 x64 DEBUG
C:\Program Files\Microsoft SDKs\Windows\v7.0>cd \tmp4
C:\tmp4>cd node-buffertools
C:\tmp4\node-buffertools>node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp info spawn python
gyp info spawn args [ 'D:\Software\NodeJS_npm\node_modules\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:\tmp4\node-buffertools\build\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'D:\Software\NodeJS_npm\node_modules\node-gyp\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\Users\Dave2.node-gyp\4.0.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\Dave2.node-gyp\4.0.0',
gyp info spawn args '-Dnode_gyp_dir=D:\Software\NodeJS_npm\node_modules\node-gyp',
gyp info spawn args '-Dnode_lib_file=node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\tmp4\node-buffertools',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'C:\tmp4\node-buffertools\build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn msbuild
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args '/clp:Verbosity=minimal',
gyp info spawn args '/nologo',
gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
C:\tmp4\node-buffertools\build\buffertools.vcxproj(3,14): error MSB4066: The attribute "Label" in element msbuild failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (D:\Software\NodeJS_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 6.1.7601
gyp ERR! command "C:\Program Files\nodejs\node.exe" "D:\Software\NodeJS_npm\node_modules\node-gyp\bin\node-gyp.js" "rebui
ld"
gyp ERR! cwd C:\tmp4\node-buffertools
gyp ERR! node -v v4.0.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
C:\tmp4\node-buffertools>
I love NodeJS. I really do.
@dperu BANG!!! You're confusing Node.js with NPM with node-gyp. This issue has nothing to do with node and everything to do with how developers are creating their modules; using platform-specific approaches and existing code-bases that have to be compiled. node-gyp is a tool they use to help automate that process (think tar-ball).
Sadly, too many developers don't use node as they should and then there are cases where they don't want to recreate (perhaps rightfully so) code in node.js that's already setup for something like c++ or another language and it has to be compiled. @TooTallNate (along with other developers/maintainers of node-gyp) have taken on quite the task in supporting those use-cases and really shouldn't be faulted. It's really up to the community to reduce their dependence on non-node solutions.
At least, that's my opinion based on what little I know :P Take it with a grain of salt.
@rainabba You are right, it's more a npm and node-gyp issue. You are right about not being faulted. I am actually thankful to the other developers who are making C++ contributions. It's been 17 years since I've compiled a C++ program. I'm coming from a C# background. But at this point I am in the process of switching stacks. I really like NodeJS and the JavaScript programming language. This particular issue is frustrating though but I imagine at some point I will be able to hack it out with all the helpful blog posts.
@Sogl I like your minimal solution, but have you been able to get it to work with node4?
@Sogl This is how the problem started for me. I was using node4 with node-gyp v3.0.3. And I started loading older versions. My current thinking on the problem is the PATH variable is not using the correct location for MSBUILD but I was busy at work and I did not get a chance to test it. In the command prompt you can enter the command: "where msbuild" to see the path location.
So here is what I discovered. I followed the other blog posts and installed Windows SDK 7. When I launch the SDK 7 command prompt having the "SetEnv.cmd" I still got errors. Here is what I was orginally trying to do from the command prompt:
C:\tmp4\npm install -g buffertools
But this failed miserablly. Then after reading some posts I did the following:
C:\tmp4> git clone https://github.com/bnoordhuis/node-buffertools C:\tmp4> cd node-buffertools C:\tmp4\node-buffertools> node-gyp rebuild
This gave me some additional error information. That information seem to indicate I was using the wrong version of MSBUILD. So I did the following:
C:\tmp4\node-buffertools> where msbuild C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe
I needed a version of SDK 7 which support the Framework\v4.0.30319. But when I installed SDK 7.1 which is supposed to support Framework\v4.0.30319 it did not create a "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin" folder as I would expect. Even though the installer said it would create the directory but it did not. And I did run the installer in Administrator mode.
So my next step was to launch the 7.0 command prompt and change the PATH. Here's the 7.0 command prompt:
C:\Windows\System32\cmd.exe /E:ON /V:ON /T:0E /K "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd"
I created a desktop icon for this, and then right-clicked and selected "Run as administrator" from the popup menu. I did the following command from the command prompt:
C:\tmp4> set PATH=C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%
So when you do "where msbuild" from the command prompt, the V4.0.30319 version was first on the list. Then I was able to do all the following with no errors:
C:\tmp4> cd node-buffertools C:\tmp4\node-buffertools> node-gyp rebuild C:\tmp4\npm install -g buffertools
C:\tmp4\npm install -g strongloop // My original intention of my efforts! Success!
One little gotcha when I got started. After you install NodeJS, you should edit the following file:
C:\Program Files\nodejs\node_modules\npm\npmrc
Change the following:
prefix=%APPDATA%\npm
To the following (or some other appropriate location):
prefix=c:\NodeJS_npm
Then I put the directory "c:\NodeJS_npm" in my PATH so the installed node modules can execute.
So this command now works:
C:\tmp4> slc loopback
IMO, doWhich function should be removed and its usage should be replaced by findMsbuild().
findMsbuild always attempts to get the latest ToolsVersion installed first, instead of selecting the one present in the PATH; which in some cases corresponds to older version. It certainly depends on the combination of installed software, for instance; it is happening in my setup very often where I normally only install a latest VS but some other runtimes setup installs old VS redistribution packs (vs2013 etc.) as well as "partial MSBuild" (v12.0 with no supporting VC libs and 14.0 targets support) installation. Currently in my setup, PATH in Git for Windows PowerShell instance suggests:
# in PowerShell
C:\> (gcm msbuild).Version # see http://stackoverflow.com/a/32522462/863980
Major Minor Build Revision
----- ----- ----- --------
12 0 31010 0
# (now I have manually set PATH to %ProgramFiles(x86)\MSBuild\14.0\Bin% in System >
# Environment Variables settings)
This change might result in performance degradation by few [milli]seconds per build, but I think it is important for correctness.
Alternatively, perhaps make the doWhich OR findMSBuild function selection optional controlled by an additional environment variable knob like $env:GYP_USE_LATEST_MSBULD=1.
@orangemocha,
Does it also eliminate the need for Python?
I'm quite new to Node, and it seems crazy to me that I have to build things that are installed via packages.
@bgSosh I haven't tried node 4 installation, but so sad to hear that problems remain.
Does it also eliminate the need for Python?
It would be good to eliminate that dependency too. Ideally you'd just need what comes with the Node installer (Node.exe + npm) and then npm install would just work.