Saturday, October 5, 2013

Bower on windows

Package Manager for The Web

I'm building a framework that one of its requirements is to support web packages dynamically. One of my friends told me about bower. I instantly adopted bower as part of my CI .
As you all don't know my daily based development environment is running on Ubuntu. With that I have less worries, until I need to go and validate my code on Windows OS...

And then I got hit...

I got a few strange errors while running my code. I start looking into it and I found out that the statement require('bower') resulting a reference error. I checked my bower installation and it looked like everything is by the book.
Finally, while googling I saw a comment that someone suggested: "for windows, try install bower locally too". Hmmm.. I did that and it works for me, for now. Might be an issue...

Still Looking for a workaround...

After installing bower globally and locally (A reminder: on windows) I still didn't get it to work and fetch my packages. Now I got error code 127. Ok that error came from the 'spawn' command probably.
First thing I checked if I can run bower from the cmd and indeed it works like a charm. So it probably related to the nodejs environment that spawn a command line to bower, for example:

bower.commands
.install(['chai'], { save: true }, {})
.on('end', function (installed) {
    console.log(installed);
});

I looked into the code error:127 and this code is about running git command. Well some will say it's about code:128
I looked for an answer and I got many that some said it helped them. In my case nothing helped and I can say that for my users I cannot give this solutions since it might not be helpful for them either.
Here are some of the solutions:
The Summary of those are, clean bower cache, put git.exe into path or use other configuration for git.


My, worked for me...

My solution to this issue is.... I just created a simple batch file that gets the bower information as arguments. Nodejs then detect that the running OS is windows and using a standard spawn command, calling to my batch file that is running externally to the nodejs.

I just hope that someone will come up with a better solution ...