Building using Node-GYP with Visual Studio Express 2015 on Windows 10 Pro x64

Posted: Oct 07, 2015 by Bryan Tong

As outlined in the issues on github. It is a bit of a pain to build projects on Windows using node-gyp and Visual Studio 2015. I will go over how I go about setting up a development environment that can build projects and I will take one of my projects that has had a hard time building on Windows 10 and get it working.

You can see the original issue here: https://github.com/nodejs/node-gyp/issues/679

There are a couple of solutions but everyone has been trying everything under the sun to get it to work and no one is sure on a solution that works from scratch.

We dont want to accept using an outdated version of Visual Studio.

Highlights Before Continuing

If you dont want to read the entire step by step instructions. I will highlight here.

You will need the following software installed first

My Current Status

Here is an overview of what I have done so far on my workstation

  • Installed Visual Studio Community 2015
  • Removed Visual Studio 2013 Express
  • Removed Visual Studio 2015 Community
  • Installed Visual Studio Express for Desktop 2015
  • Set the Following Environment Variable GYP_MSVS_VERSION=2015
  • Using Python 2.7

Computer History

This isnt a clean workstation. I have been using Windows 7 Pro 64-bit on this computer since 2012 and I have had Node working and building projects on here for quite some time. After my upgrade to Windows 10 I could still build using Node 0.10 and Visual Studio Express 2013.

I use nodist so I went ahead and bumped my version to latest

$ nodist selfupdate
$ nodist latest
$ npm -g update

Issue from older NPM

I then tried to build my project using the npm install --msvs_version=2015 and I see the following on bcrypt.

> [email protected] install C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt
> node-gyp rebuild


C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt>node "C:\nodist\bin\node_
modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebui
ld
gyp http GET //nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz
gyp http 200 //nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz
gyp http GET //nodejs.org/dist/v4.1.2/SHASUMS.txt
gyp http GET //nodejs.org/dist/v4.1.2/SHASUMS.txt
gyp http GET //nodejs.org/dist/v4.1.2/node.lib
gyp http GET //nodejs.org/dist/v4.1.2/x64/node.lib
gyp http GET //nodejs.org/dist/v4.1.2/node.lib
gyp http GET //nodejs.org/dist/v4.1.2/x64/node.lib
gyp http 404 //nodejs.org/dist/v4.1.2/SHASUMS.txt
gyp WARN install got an error, rolling back install
gyp http 404 //nodejs.org/dist/v4.1.2/node.lib
gyp http 404 //nodejs.org/dist/v4.1.2/SHASUMS.txt
gyp http 404 //nodejs.org/dist/v4.1.2/x64/node.lib
gyp http 404 //nodejs.org/dist/v4.1.2/x64/node.lib
gyp http 404 //nodejs.org/dist/v4.1.2/node.lib
gyp ERR! configure error
gyp ERR! stack Error: 404 status code downloading SHASUMS.txt
gyp ERR! stack     at Request.<anonymous> (C:\nodist\bin\node_modules\npm\node_m
odules\node-gyp\lib\install.js:316:18)
gyp ERR! stack     at emitOne (events.js:82:20)
gyp ERR! stack     at Request.emit (events.js:169:7)
gyp ERR! stack     at Request.onResponse (C:\nodist\bin\node_modules\npm\node_mo
dules\request\request.js:832:10)
gyp ERR! stack     at ClientRequest.g (events.js:260:16)
gyp ERR! stack     at emitOne (events.js:77:13)
gyp ERR! stack     at ClientRequest.emit (events.js:169:7)
gyp ERR! stack     at HTTPParser.parserOnIncomingClient (_http_client.js:415:21)

gyp ERR! stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)

gyp ERR! stack     at Socket.socketOnData (_http_client.js:305:20)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command "C:\\nodist\\v\\nodev4.1.2\\node.exe" "C:\\nodist\\bin\\node_mo
dules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt
gyp ERR! node -v v4.1.2
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the bcrypt 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 bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 10.0.10240
npm ERR! command "C:\\nodist\\v\\nodev4.1.2\\node.exe" "C:\\nodist\\bin\\node_mo
dules\\npm\\bin\\npm-cli.js" "install" "--msvs_version=2015"
npm ERR! cwd C:\Users\JT4\WebstormProjects\oose
npm ERR! node -v v4.1.2
npm ERR! npm -v 1.4.6
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\JT4\WebstormProjects\oose\npm-debug.log
npm ERR! not ok code 0

This seems a little different than what I am seeing on others but it still may be related so I am going to explore.

I solved this issue using the latest version of NPM.

Here were my install instructions.

Visit this page: https://github.com/npm/npm/releases I grabbed 3.3.6 as it was the latest in the 3.x branch: https://github.com/npm/npm/archive/v3.3.6.tar.gz

Once I had that I installed it.

In my case, I am using nodist so I did the following

  • Went to C:\nodist\bin\node_modules\npm and renamed it to C:\nodist\bin\node_modules\npm_old
  • Created a new folder C:\nodist\bin\node_modules\npm
  • Extracted the contents of the npm-3.3.6 folder into C:\nodist\bin\node_modules\npm
  • Went back to my project
  • npm install --msvs_version=2015 and the install worked successfully.

Here is my console output.

C:\Users\JT4\WebstormProjects\oose>npm -v
3.3.6

C:\Users\JT4\WebstormProjects\oose>npm install

> [email protected] install C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt
> node-gyp rebuild


C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt>if not defined npm_config
_node_gyp (node "C:\nodist\bin\node_modules\npm\bin\node-gyp-bin\\..\..\node_mod
ules\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.
  blowfish.cc
  bcrypt.cc
  bcrypt_node.cc
..\src\bcrypt.cc(232): warning C4267: '=': conversion from 'size_t' to 'unsigne
d char', possible loss of data [C:\Users\JT4\WebstormProjects\oose\node_modules
\bcrypt\build\bcrypt_lib.vcxproj]
  win_delay_load_hook.c
     Creating library C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt\bu
  ild\Release\bcrypt_lib.lib and object C:\Users\JT4\WebstormProjects\oose\node
  _modules\bcrypt\build\Release\bcrypt_lib.exp
  Generating code
  Finished generating code
  bcrypt_lib.vcxproj -> C:\Users\JT4\WebstormProjects\oose\node_modules\bcrypt\
  build\Release\\bcrypt_lib.node
[email protected] C:\Users\JT4\WebstormProjects\oose
??? [email protected]
  ??? [email protected]
  ??? [email protected]

npm WARN EPACKAGEJSON [email protected] No license field.

C:\Users\JT4\WebstormProjects\oose>
C:\Users\JT4\WebstormProjects\oose>

Okay great! So now I have builds working on my local computer. The next step is to overview the steps to get this working on a fresh install.

Fresh Windows Installation

Now I will go over the complete installation instructions to setup a build environment from scratch!

To start out I am using Windows 10 Pro x64 ISO to do the installation. I am installing on to VirtualBox Version 5.0.6 r103037.

I created the VM using standard settings and now I am going to go through the installation.

Windows 10 Install Step 1

Windows 10 Install Step 2

Windows 10 Install Step 3

Here I choose "Custom: Install Windows Only" and then continue

Windows 10 Install Step 4

Windows 10 Install Step 5

Windows 10 Install Step 6

Windows 10 Install Step 7

Windows 10 Install Step 8

Here I chose, that "I own it" I skipped the account creation step. Then I entered "Coco" for a username and no password.

Windows 10 Install Step 9

Windows 10 Install Step 10

I Install Chrome first just to get a browser that I can use.

Windows 10 Install Step 11

Now I install the Virtualbox Guest Additions and reboot.

Windows 10 Install Step 12

Now we are going to install git. I grab the file from here: https://git-scm.com/downloads

Windows 10 Install Step 13

I select to use the Linux tools from the CLI.

Windows 10 Install Step 14

I check out lines as is and commit UNIX style (this seems to keep everything happy, unless you are using a code editor that cant handle UNIX style line endings). I use notepad++ and Webstorm.

Windows 10 Install Step 15

Next I go here: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx

And I download the community edition. Once the download completes I star the installation and select "Custom" from the install options.

Windows 10 Install Step 16

Make sure to select the Visual C++ and Python Tools. You can see my complete list of selections in the following two images.

Windows 10 Install Step 17

Windows 10 Install Step 18

Now with the install underway this can anywhere from 30 minutes to 2 hours (dont ask me, ask microsoft) During that time I am going to work on getting the rest of our platform together. However, you can wait until it finishes if you prefer.

Next, I start the command prompt and return it to legacy mode (this helps Webstorm as well as npm)

Windows 10 Install Step 19

Now I go here: https://github.com/marcelklehr/nodist and get ready to checkout the git repo by opening a command prompt and coding the following

$ cd \
$ git clone https://github.com/marcelklehr/nodist.git

This will install nodist to C:\nodist which we will use to obtain our node versions. (Of course you could also use the installer from the Node.js website. However for a development environment this makes much more sense.

Windows 10 Install Step 20

Now we must add some envrionment variables to get nodist to work correctly. We need to add the following.

  • System -> Path we need to append ;C:\nodist\bin
  • System -> NODIST_PREFIX set to C:\nodist

To get to the interface to make these changes Right click on the Windows Icon at the bottom left, then click "System" next click "Advanced System Settings" and then finally click "Environment Variables"

Windows 10 Install Step 21

Windows 10 Install Step 22

After setting the environment variables we are get nodist initialized and get the latest version of node installed.

NOTE In my environment for some reason nodist did not download a complete copy of Node 4.1.2 when running nodist latest I had to go to C:\nodist\v and delete the 4.1.2 folder and run nodist latest again. After that it worked. There is an issue filed against this here: https://github.com/marcelklehr/nodist/issues/93

Windows 10 Install Step 22.5

Now it is time to install NPM with the latest version. Right now nodist comes with version 1.4.6 which is too old to work with the latest versions of Node and Node-GYP. Thus, we must overlay the latest version on our system.

Download NPM from here: https://github.com/npm/npm/releases

I used the ZIP for easier use with Windows: https://github.com/npm/npm/archive/v3.3.6.zip

After downloading the ZIP I went to C:\nodist\bin\node_modules in Windows explorer and renamed npm to npm_old. Then I created a new folder at this location named npm. Then I extracted the zip to C:\nodist\bin\node_modules\npm This extracts a folder called npm-3.3.6 to the location. I had to go inside npm-3.3.6 and move all the files and folders to C:\nodist\bin\node_modules\npm.

Once that is complete NPM will be working as the new version.

Windows 10 Install Step 23

Windows 10 Install Step 24

Windows 10 Install Step 25

Windows 10 Install Step 26

Windows 10 Install Step 27

We must install Python before we can use Node-GYP.

Visit this page: https://www.python.org/download/releases/2.7/

I downloaded this file: https://www.python.org/ftp/python/2.7/python-2.7.amd64.msi

Then I ran through the installer.

NOTE This was about the time the Visual Studio installer was finishing up. It has to finish before Windows will let this installer run.

Windows 10 Install Step 28

Getting close to the end here. We have to add another Environment Variable like before.

  • GYP_MSVS_VERSION=2015

Windows 10 Install Step 29

Now, we are ready to see if we can hit pay dirt. I will outline my steps related to the next image.

I open a command prompt as "Administrator" by right clicking cmd.exe and choosing "Run as Administrator".

I always pin the cmd.exe to the task bar. You can do this by searching cmd in the Windows Start menu and then right clicking and clicking "Pin to Taskbar"

With the administrator prompt open I execute the following.

$ cd \Users\Coco
$ mkdir projects
$ cd projects
$ git clone https://github.com/eSited/oose.git
$ cd oose
$ npm install

Provided everything works correctly you should get a successful build.

Windows 10 Install Step 30

The example project I used relies on the npm bcrypt package: https://www.npmjs.com/package/bcrypt

This is the most often complaint against not getting node-gyp to work on Windows 10.

It looks like we have working build environment. I hope some day this process gets simpler!