Thursday, December 15, 2011

Debugging native node modules loading failure on windows

If you ever need to build a module that requires another library (e.g. openssl, ict, expat etc) you may receive an “Out of memory” error when you require the file. This is unfortunately a generic error on windows but you can fire up visual studio and debug node (attaching to a process) and you can can see there the exact system error number (sys_errno) by adding a breakpoint in deps\uv\src\win\error.c when uv translates the error code (uv_translate_sys_error).

In my case I was receiving the 126 error code which I looked up at http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx and then I figured that I hadn’t restarted the console after I added the referring dll file path in my enviroment PATH variable… I opened a new console, verified that the dll’s path is in my PATH variable and the module loaded just fine…

Another common loading problem devs are facing is during the deployment of their node modules. The most common cause of this weird behavior is that you have your modules built in debug mode that reference the msvcr100d.dll instead of the msvcr100.dll which you might be deploying with your node module... Dependency walker will help you out to locate such errors indicating which references cannot be found and bundle them with your deployed module.

Hope this helps a bit when you try to debug weird loading errors.

2 comments:

Adam said...

Thanks for your post! How did you find symbols for Node? I have the source through C:\Users\me\.node-gyp\0.8.15\src

I've added that dir to my solution under Debug Source Directories

But I can't find symbols so I can't set a breakpoint.

I'm pretty noob with C++ so it's probably easy. Thanks for any help you can give!!

Andreas Botsikas said...

Hi Adam,

Actually I built node js from source. I am not sure that node-gyp brings the debug symbols with it. It is fairly easy to build node.js from source (just run the bat file in the root of the repo) and you will be able to attach to the process and do all the debugging you want.