`var thing = require('./thing');` style requires throw Module not Found errors #227

Techwraith opened this Issue Oct 18, 2012 · 10 comments


None yet

3 participants



in node_modules/test/

var test = {};
test.thing = require('./thing');

module.exports = test;


in node_modules/test/

module.exports = function thing (foo) {
  console.log("thing", foo);


When doing browserify -r test -o test.js and then loading test.js on the page, then doing:

var test = require('test');


I get this error:

Error: Cannot find module './thing'

Any idea what might be going on here?


I think I have a solution, but I need to test it a lot more. I believe the module resolution system incorrectly thinks that any ./* module in a module should be based off the root of the apps directory. I have a test that changes these requires into "module/thing" path syntax and it seems to work for my use-case.


Let me fork and add the fix, the problem is that it actually removes code so I think it might break other stuff.


that I need to test.


Staged at PaulKinlan@0207df2 - all tests pass although it feels a bit hacky. For every module that is a submodule I append the target path so the data is accessed via require "/abc/thing" if the module is abc and the child module is "thing"


@substack What do you think of this?


Thanks @PaulKinlan This totally fixed it for me. @substack If this looks ok to you, I'd recommend merging this pull request. All tests pass and it made my use case work.


@substack I have created a pull request for this. #231


Sorry for the delay on this and thanks for posting. v2 should fix this bug since the require rebasing with commondir doesn't happen for the module resolution since the require graph is completely resolved at bundle time instead of runtime now.

@substack substack closed this Feb 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment