You might have heard the Unix Bash Shell is now coming to Windows. To be more specific a whole Linux sub system based on the Ubuntu distribution comes to Windows. This addition to Windows was announce at this years Build Conference and I knew exactly how this would match to my clients and other people in the SharePoint Community. Especially with the new SharePoint Framework you should know this option because it makes many things easier using NodeJS on Windows.
NodeJS and Windows
Personally I started to use NodeJS for client side development a couple of years ago. In addition I work with clients that use the same development pattern as I do for more than a year now. While I am using NodeJS on Mac, my customer use NodeJS on Windows. To be fair, on Windows, this doesn’t really work as smoothly as expected.
Microsoft made a really great involvement to bring NodeJS to Windows and integrate some part in Visual Studio. In future I think Bash on Windows will solve a lot of gaps that currently without a doubt exists.
You still will have the choice to use NodeJS directly in Windows or choose the smoother path by using the Linux sub system for Windows.
Let’s list some of the issue I recognized when working on Windows.
NodeJS is platform independent?
In addition many high performance libraries and tools use Python or C and compile itself directly on the target system.
This is actually the part where it gets tricky. The default Yeoman generator uses browser-sync.io or SASS. Those two parts directly compile some node extensions from source.
The responsible for this behavior is ‘node-gyp’. It is a cross-platform command-line tool written in Node.js for compiling native add-on modules for Node.js.
On Windows it requires to have Visual Studio or a Visual C++ Runtime Library installed. In addition you need to have Python Version 2.7 installed. It’s a really old version on Python but NodeJS required this specific version. Both environments are optional but nowadays more of the required kind, from my point of view.
You can avoid the additional installation steps if you use the Linux sub-system for Windows. A C/C++ compiler is already installed as well as Python 2.7. It is part of every Linux distribution nowadays and used in many ways there.
Once again, NodeJS is platform independent but sooner or later you will face the boundaries on Windows. A thing that Bash on Windows solves in future for you.
Performance through native NodeJS Add-ons
The major benefit of those native compiled add-ons is performance. Browser-sync.io, SASS, Websocket.io and many other extensions use it.
For example, SASS was written in Ruby and the problem is here if you have large projects the compilation SASS to CSS files might take a while. To wait one second is even too much.
The solution is a C/C++ library named ‘libsass’ that does the compilation of the SASS files instead. The compilation will then only take milliseconds instead of seconds. Much faster then the Ruby compilation.
Those add-ons makes absolute sense in case of performance and constantly development without manual compilation. The downside is you need to have a C or Phyton compiler installed on your local machine.
The file system and case sensitivity
On a Windows the file system you have some limitations that doesn’t exist under UNIX but those exactly can cause some problems when using NodeJS.
The first issue with the file system is that Windows is case insensitive but case aware. So what does it mean.
Let’s say you have a web application in the root folder is an ‘index.html’ file stored. On a Windows system you can have only have one file named ‘index.html’. On a Linux, BSD or MacOS you can have ‘index.html’ and next to that you can have additional files named ‘Index.html’, ‘iNDEX.html’, ‘index.HTML’ or any other permutation of the name ‘index.html’. All those files are stored in the same directory and each file can have an individual content.
You might think. Good to know but I have only one file. This is true, but you might do code sharing with someone on a Mac, Linux or BSD. In this case your code might break, because when you request a file named ‘Index.html’ on a Linux system and the file is named ‘index.html’. The file simply cannot be found.
This currently cause some troubles when you works with some yeoman generator built on Windows.
The file system and the max path problem
Node modules you use in your application or Yeoman generator can have a highly nested structure and sometimes long directory names. Take the default node modules folder for example. This folder is named ‘node_modules’. Inside this folder other node modules can exist and in those node modules again other node modules might exist. You normally not worry about that but the path to get there might become really long.
On Windows the maximum path length can only contain 260 characters. When you use NodeJS or Yeoman Generators you might need to clean the node modules directory from time to time. When you try to clean up the node module folder in your applications root directory with all sub directories you will fail in some cases. The origin of this problem is that Windows can only work with paths that not exceed the 260 character length limit. This problem is also know as the MAX_PATH limitation.
In the latest Windows Insider Build you can change this behavior through a group policy. To be able to change this is an indication for two things. First, it will help with NodeJS. Second and this is the most likely reason the bigger use is for the Linux sub system on Window.
This limitation doesn’t exist on Linux and especially not on the Linux sub system for Windows. Again, a point on the score table using Bash on Windows.
The new SharePoint Framework
I’m sure that Microsoft will put a lot of effort in their new SharePoint Yeoman generator. As far as I have seen it use only native NodeJS. This might have impact on performance and some parts might run slower then expected. A possible side effect when using just pure NodeJS because it needs to support Windows users too. While I tried to improve the Yo Office generator. I had a great discussion with Jeremy Thake on the problems with NodeJS users on Windows.
One thing that is an indictation for me that no ‘node-gyp’ is involved is that all samples I have seen so far use just use LESS instead of SASS. Nowadays LESS is a little bit outdated because the performance on larger project is not that good. A reason why many people switched to SASS nowadays and forgot about LESS. Popular examples for project that recently switched from LESS to SASS are Bootstrap or Office UI Fabric.
Another big benefit of Bash on Windows
If you messed up your Linux configuration you can store your source code outside on the regular Windows file system and can whip nodeJS and the whole Linux installation pretty easily. On Windows you have messed up probably your operating system with the NodeJS installation, the Python installation or the C++ runtime. Those things are especially require if you don’t like to use just the yeoman generator without Visual Studio installed.
What do we end up here? No matter, how this new SharePoint Framework and Yeoman generator works. The only thing I can recommend is to take a look into Bash on Windows. Especially if you like to use other state of the art yeoman generator for your development. Most of them are effected by the limitation of NodeJS on Windows.
I really love that Microsoft use these tools nowadays and they will close a gap between traditional ASP.net development and move more toward a modern web development approach. Many of us already used in SharePoint nowadays.
In the mean time I test every new version of the Linux sub system on Windows because there are currently some issues that prevents you from using NodeJS on Windows. Especially to upgrade to the latest version of NodeJS.
In the most recent version of bash on Windows they fixed some issues and I will show how to configure NodeJS there as well as yeoman. In the mean time check out the lasted Office Dev PnP Web Cast Waldek Mastykarz and Vesa Juvonen did or check out “Getting started with web stack in SharePoint development“.
If you like to know more on Bash on Windows I would recommend a the web cast Scott Hanselman did during the Build conference.