Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

allow to require modules in working directory #11653

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
6 participants

jamhed commented Sep 27, 2013

lookup for modules not only in node_modules directory,
but also in current directory.

@jamhed jamhed allow to require modules in working directory
lookup for modules not only in node_modules directory,
but also in current directory.
d33744f
Contributor

hexid commented Oct 1, 2013

Couldn't this also be done by just adding _paths.push(joinPath(dir, request)); after Line 229?

jamhed commented Oct 1, 2013

It could, but I've decided to keep original behaviour: first to lookup module in node_modules folders, and only after that do more search.

Collaborator

JamesMGreene commented Oct 1, 2013

This is the logic that we should be trying to match: http://nodejs.org/api/modules.html#modules_all_together

jamhed commented Oct 1, 2013

I'm not so sure. Suppose you wrote a custom module like I did. Then you want to include it in a script in a same folder. So you do require('module'). But it doesn't work with 'Error: Cannot find module'. Wat? Relative path is correct, using global paths is a bad idea at all, what's going on, you think. And then you suddenly figure out that every module should be in node_modules folder, to be required by phantomjs. Just why?

Contributor

hexid commented Oct 1, 2013

If you use require('./module'); then it will load.

You could also use:

require.paths.push('.');
require('module');

jamhed commented Oct 1, 2013

I know the workarounds, thank you.

Owner

ariya commented Oct 9, 2013

Was there a feature request filed for this?
Can you add some basic tests?

jamhed commented Oct 9, 2013

On 09.10.2013 11:45, Ariya Hidayat wrote:

Was there a feature request filed for this?

I suppose no.

Can you add some basic tests?

I will.

Owner

ariya commented Oct 9, 2013

Probably file a feature request first. Check the contribution guide, we don't typically have patches flying around without initial justification (bug fix or enhancement) agreed on.

jamhed commented Oct 12, 2013

On 09.10.2013 21:06, Ariya Hidayat wrote:

Probably file a feature request first. Check the contribution guide, we don't typically have patches flying around without initial justification (bug fix or enhancement) agreed on.

What's the proper way to file a feature request?

jamhed commented Oct 16, 2013

I see no discussion of "feature request" in mailing list. What's next?

LinusU commented Jun 18, 2015

@jamhed That's no workaround, that is the intended behaviour.

You are not suppose to put anything into the node_modules folder manually, that's where npm installs your dependencies.

Put your scripts in the same folder and require with relative path, e.g. wat.js -> require('./wat').

Collaborator

zackw commented Dec 22, 2015

It appears to me that this patch should not be merged, because we are trying to match the behavior of node.js, which intentionally does not do this. If I'm mistaken, feel free to reopen.

@zackw zackw closed this Dec 22, 2015

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