Article
15 comments

Browser-sync and node-gyp need some Vitamin C to run on Windows

Recently I had and issue with browser-sync on Windows. The problem came from node-gyp, a cross platform compiler that is integrated in Node.js. Exactly this module of Node.js was throwing an error that stated ‘Python is missing’ on Windows.
Actually the thing is a little bit more tricky and over the last couple of days I read many problems with node-gyp and Windows. Some mentioned to install Visual Studio Community Edition as well as other components found on the Microsoft Web Site.
The only thing Windows needs is just some Vitamin C in the form of a Visual C++.

Partially wrong documentation on browser-sync.io

When you take a look on the browser sync documentation page it states that there are might some troubles with Windows. If you are running into the issue of your Windows update not downloading then click the link above to resolve the issues. The recommended workaround is to install Visual Studio because this will install the required Visual C++ runtime libraries. This library is used by the native build tool node-gyp.
The easiest way to get the runtime libraries installed is to install the so called “Microsoft Visual C++ Redistributable Package”. This installer has everything needed included. The latest Version can be found on the Knowledge Base article.
After this package have been installed everything works fine.

Testing procedure

To be honest. Whenever I tried to browser-sync or Yeoman generators on windows I always had Visual Studio installed too. In this case you don’t have troubles with with all that stuff and Visual C++ is already installed.
To reproduce the behavior mentioned above I installed a fresh new Windows 10 virtual machine and started to install from scratch.
First, I installed ‘Node.js’. I tested it with the mature and dependable version (Version 4.x.x) as well with the version that included the latest features (Version 5.x.x.) of ‘Node.js’.
After that I installed Git and Yeoman plus the default web application generator. Needless to say that this default generator includes browser sync as its core web server.
The I created the first project with this generator and guess what? I failed with the following error.

> [email protected] install C:\test\webapp\node_modules\bufferutil

> node-gyp rebuild
C:\test\webapp\node_modules\bufferutil>if not defined npm_config_node_gyp (node “C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js” rebuild ) else (node rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can’t find Python executable “python”, you can set the PYTHON env variable.
gyp ERR! stack at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:116:14)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:71:11
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command “C:\\Program Files\\nodejs\\node.exe” “C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js” “rebuild”
gyp ERR! cwd C:\test\webapp\node_modules\bufferutil
gyp ERR! node -v v5.5.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`

Right after installing the latest Version of Visual C++ all the problems were gone. Because now browser sync found a C++ compile and a environment to run as mentioned on their web site.
Further updates of Visual C++ will be automatically installed through Windows update so nothing to worry about.

Visual C++ installed on Windows 10

Visual C++ installed on Windows 10

 

*** Update 1.2.2016 *** The problem come back when you use browser-sync without yeoman generators. The reason for this python message is because some optional components require python to be install but those components are not required to run browser-sync. This can be avoided if browser-sync will is installed through the following command.

npm install browser-sync --no-optional

node-gyp – do I need Python?

It depends. ‘node-gyp’ is a cross-platform command-line tool written in ‘Node.js’ for compiling native add-on modules for ‘Node.js’. It bundles the gyp project used by the Chromium team and takes away the pain of dealing with various differences in build platforms.
That is what the official Github project page of node-gyp says. The developers also recommend to install Python to use the full spectrum of node-gyp.
In case of browser-sync Python is not required because some dependencies will be compiled through C++ but not Python. If you are dealing with other projects Python might needs to be installed on Windows too.
From my perspective the origin of the error message comes from the fact that no C++ compiler could be found and node-gyp try  to compiled it with Python as the last option.
On Linux and OS X compiler for Python as well as C++ are integrated directly in the operation system.

15 Comments

  1. Hi Stefan,

    I already had the C++ 2008 runtime installed and just added the x64 c++ 2013-Runtime – as seen in you screenshot. But I still get the node-gyp errors 🙁

    Reply

    • After the installation you should try:

      “`npm rebuild“`

      This might be required and will recompile all C++ base Node.js components.
      /Stefan

      Reply

      • OK – no luck. bufferutil and utf-8-validate are failing at “node-gyp rebuild”.

        Reply

          • D:\projects\node-gyp-test>node -v
            v5.5.0

            D:\projects\node-gyp-test>npm -v
            3.3.5

            D:\projects\node-gyp-test>ver

            Microsoft Windows [Version 10.0.10586]

          • Hi Henning,

            first, thank you for your feedback.

            This is my exact setup:

            C:\test\webapp>npm -v & node -v & npm list browser-sync & ver > test.txt
            3.3.12
            v5.5.0
            C:\test\webapp
            └── [email protected].1
            Microsoft Windows [Version 10.0.10240]

            Seems like my npm is a little bit newer than yours. One thing I haven’t had to do was to upgraded npm bundled node-gyp version but this can be done manually. npm provides information on [how to upgrade](https://github.com/nodejs/node-gyp/wiki/Updating-npm's-bundled-node-gyp).

            The current version of node-gype I use is: 3.2.1

            /Stefan

          • Well, I tryed updating npm (using “npm install npm -g”), which bumbed npm to 3.6.0) But still no luck with the node-gyp error.

          • now I did – running “npm install -g node-gyp@latest”. So now I have node-gyp 3.2.1, npm 3.6, node 5.5.0 🙁

          • and after that you tried “npm rebuild”? Have you tried to “run as administrator” are you using the classical cmd or powershell?
            Strange issue it is.

          • Strange problem. My system was a complete fresh windows setup and installed it in that way without any problem.
            I had another problem with Visual Studio Online and there I installed a couple of packages directly in the build.
            Have you checked for outdated packages through.
            ‘npm outdated –global’
            Is browser sync install globally?

          • npm outdate -global doesn’t Show anything. I installed browser-sync local.

          • Dug deeper and figured it out now. The problem are the optional dependencies that are not required to run browser-sync.
            When you browser-sync will be installed

            “`npm install browser-sync –no-optional“`

            No exception will be thrown during installation and browser-sync works fine.
            The problem is that the default Yeoman generators handle this differently somehow.
            I will take a look into this too and open up an issue on the optional stuff.

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.