dinsdag 24 juli 2012

I wanted to add ldapjs to my Windows node.js project but...

I wanted to add ldapjs to my node.js project but encountered the issue that it does not install under windows node version 8. As stated there, the cause is that one of ldapjs dependency, dtrace-provider, is built using node-waf which does not work on Windows.
As a result, "npm install ldapjs" fails
977 error node -v v0.8.2978 error npm -v 1.1.36979 error code ELIFECYCLE980 error message dtrace-provider@0.0.9 install: node-waf clean ; node-waf configure build980 error message cmd "/c" "node-waf clean ; node-waf configure build" failed with 1981 verbose exit [ 1, true ]
It appeared that the solution is to use gyp instead of node-waf for building dtrace-provider. bfar did a part of the job by forking it and adding the gyp config file.

DailyJS "Windows and Nodes: Addons" describes how make the gyp compilation working on Windows by installing Python and Visual C++.
So I downloaded the sources of bfar's fork and executed this last tutorial and it worked! I got the dtrace-provider compiled.
The, "npm install ldapjs" on my project worked after copying the built dtrace-provider module folder under my node_modules folder. 
However, executing again the command from scratch (by emptying node_modules) was failing and the copy of the manually built dtrace-provider was not statisfactory (too many manual steps).
In order to streamline a little bit more the process, I modified the package.json of dtrace-provider and change the script command for the install stage. So I replaced
"scripts": { "install": "node-waf configure build" }
by
"scripts": { "install": "node-gyp rebuild" }
The updated package.json is here.
Finally, in my node.js project, I added the dependency to my fork of blar so that my project package.json contains
"dependencies": {
    "dtrace-provider": "git://github.com/itoche/node-dtrace-provider.git#binding-gyp"
     , "ldapjs": "0.5.4"
 }
Now, "npm install ldapjs" works fine.