This repository has been archived by the owner. It is now read-only.

expose a module.resolve method, or require.resolve(path, startPath) #3285

lfdoherty opened this Issue May 18, 2012 · 2 comments


None yet
3 participants

It's almost possible to build lookup of other resources (like browser-side javascript resources) on top of the node.js require system. The only thing missing is the ability to resolve lookups relative to a module.

Adding the following to module.js exposes that functionality cleanly:

Module.prototype.resolve = function(path) {
return Module._resolveFilename(path, this);

Alternatively, changing require.resolve to take a path from which to start would be an even more flexible solution.

moll commented Apr 21, 2013

This is something I just needed myself as well, so I'm definitely for adding the resolve method to Module.prototype.require. The current work-around of using Module._resolveFilename directly with, for example, the given module.parent is obviously risky.

isaacs commented Apr 21, 2013

We won't be adding any API or functionality to the module system any time soon. The algorithm is pretty simple, and easy to implement in userland modules (as browserify does).

@isaacs isaacs closed this Apr 21, 2013

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.