Seriously debugging node.js 'Cannot find module xyz/abcd'

module, node.js, require

Solution

By investigating more, I think I found a good technique :

export NODE_DEBUG=module
node my_script.js

gives such interesting traces :

looking for "/(...)/tests_init.js" in ["/home/(me)/.nave/installed/0.10.24/lib/node","/home/(me)/.node_modules","/home/(me)/.node_libraries","/home/(me)/.nave/installed/0.10.24/lib/node"]

And BTW, it shows that node is not searching at all where I thought it was. Time to investigate...

[edit] end of the story :

1) it appears that node is not treating well modules installed with `npm link`. `require(...)` sometimes fails to select files from inside a npm-linked module. I have no desire to investigate further the exact error conditions, I'll just conclude that `npm link` is very brittle.

2) beware of node looking for node_modules all the way into the parent dirs of current working directory ! I found that modules from parent folders of my app where sometime selected !

Problem

I have the `Error: Cannot find module xyz/abcd` error. YES, the required module is installed. According to the pseudo-code of module.require here, it should work. I tried to dive inside `require()` to understand why it can't find my file. My node debugger won't step into require(). I've tried the `strace / grep NOENT` technique whithout success either. Any idea how to troubleshoot a nasty `require()` failure ? Note : just in case : the error comes from a file node_modules/xyz/a requiring xyz/b. It should work according to the doc.

Original source