RecentlyI have posted instructions on how to install Node.js and CoffeeScript on Windows using Cygwin. It results in fully-functional Node.js and CoffeeScript, but the process is rather cumbersome.
There is another way to get CoffeeScript working on Windows suggested by alisay and briefly described here, which is based on usage of the experimental Windows version of Node.js. While the way is not recommended as default by both CoffeeScript author (Jeremy Ashkenas) and Node.js team, it works more or less for me. There are things (e.g. CoffeeScript –watch option) that don’t work, there are things (e.g. Cake build task) that I managed to make working after doing certain tweaks in CoffeeScript files. But if you need just basic function – compilation – it works fine as well as a number of other functions.
Still, If you look for fully-functional Node.js as well, you need to install it over Cygwin as described in the previous post.
So here is how to make CoffeeScript working on Windows in a simple way.
Download Windows version of Node.js from here and download CoffeeScript from here (look for “Latest Version” link).
Put node.exe file into any directory you find it appropriate (e.g. I have used c:\tools\node). Unzip CoffeeScript in any other directory (I have used c:\dev). Go to the directory where you put node.exe and create coffee.cmd file.
In my case coffee.cmd looks like this:
@echo off node.exe C:\dev\jashkenas-coffee-script-1a652a9\bin\coffee %*
Here C:\dev\jashkenas-coffee-script-1a652a9\bin\ is a path to coffee file which is located in bin directory of CoffeeScript dirstro. Substitute it with the actual path you have in your case.
Add the folder where you put coffee.cmd to Windows PATH (see instructions here), restart your computer.
Now you are ready to test your CoffeeScript compiler. Create test.coffee file in any directory, put “2+2″ expression in it. Start Windows command prompt, go to the directory where you put the file and run command coffee –compile test.coffee. As a result of this a new test.js file will appear in the directory. The file should contain following JavaScript code:
(function() {
2 + 2;
}).call(this);
This means you have installed CoffeeScript successfully and you can compile CoffeeScript files.
However this does not mean that each and every option of CoffeeScript compiler works on Windows in this setup as well. For example, I could not make working –watch option (maybe you will be more lucky).
CoffeeScript comes with its own build tool named Cake (see here instructions to it). Let’s make it working as well. First create cake.cmd file in the same folder where you have coffee.cmd and put this in the file:
@echo off node.exe C:\dev\jashkenas-coffee-script-1a652a9\bin\cake %*
Now let’s test it. Open Windows command prompt. Go to the root folder of the unzipped CoffeeScript distro (there should be file named Cakefile). Run cake command. The output should show you a list of all build tasks in the Cakefile:
cake install # install CoffeeScript into /usr/local (or --prefix) cake build # build the CoffeeScript language from source cake build:full # rebuild the source twice, and run the tests cake build:parser # rebuild the Jison parser (run build first) cake build:ultraviolet # build and install the Ultraviolet syntax highlighter cake build:browser # rebuild the merged script for inclusion in the browser cake doc:site # watch and continually rebuild the documentation for the website cake doc:source # rebuild the internal documentation cake doc:underscore # rebuild the Underscore.coffee documentation page cake bench # quick benchmark of compilation time cake loc # count the lines of source code in the CoffeeScript compiler cake test # run the CoffeeScript language test suite cake test:browser # run the test suite against the merged browser script -p, --prefix set the installation prefix for `cake install`
If you see such output, it means you can run Cake.
Unfortunately not all tasks of regular Cake build files will work on Windows with our setup. To make them working we have to tweak them a bit. Let’s use Cakefile we have with CoffeeScript distro. For example, if you try to execute build task by typing cake build you will get this error message:
CreateProcessW: %1 is not a valid Win32 application.
This happens since at some point Cake tries to execute certain Linux/Unix commands that obviously don’t work on Windows. To fix this particular problem open Cakefile in a text editor. Find following line:
proc = spawn 'bin/coffee', args
Replace it with this:
proc = spawn 'coffee.cmd', args
Run Cake build again. To verify that it worked fine, take a look at lib directory. There should be JavaScript files with timestamp corresponding to the time when you run the build process. If you see them, congratulations – you just built CoffeeScript.
This is not the only place in Cakefile which won’t work on Windows. Look for all uses of spawn and exec functions and adjust them properly. For example this exec function call won’t work on Windows:
exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
since there is no sudo command on Windows etc.










