>From a's point of view, there is no c.  But this works fine.  Observe:

https://gist.github.com/4259909

Each module can load whatever is in its node_modules folder (or
parents), no matter where the module lives.  Then that module, in its
actual realpath home, can load whatever is in its node_modules folder
(or parents), no matter where they actually live.

This is required because of the way that executables are typically
linked.  On Unix, you have something like:

/usr/local/node_modules/foo/bin/foo.js

which does `require("../lib/foo-internals.js")`.

That script is linked to

/usr/local/bin/foo

If we didn't realpath, then it'd be looking for
/usr/local/lib/foo-internals.js instead of
/usr/local/node_modules/foo/lib/foo-internals.js.

Does that make sense?


On Mon, Dec 10, 2012 at 2:41 PM, Vojta Jína <[email protected]> wrote:
> Hey, I have a question regards require() and resolving symlinks.
>
> Consider this structure:
> a/main.js
> a/node_modules/b/index.js --> /b/index.js
> b/index.js
> b/node_modules/c/index.js --> /c/index.js
>
> $ cat /a/main.js
> require('b');
>
> $ cat /b/index.js
> require('c');
>
> $ node a/main.js will fail to load 'c', because (as described in
> http://nodejs.org/api/modules.html) it resolves symlinks and then does look
> up relatively to the file content - symlink destination (not the symlink
> path).
>
> What are the reasons for this behavior ? I would expect otherwise.
>
> Then, if you wanted to resolve deps relatively to the symlink destination,
> you would create symlinks to directories, rather then individual files.
>
> I'm asking, because the current behavior makes it very difficult to enable
> local modules with our build tools + scm.
>
> Thanks a lot for help,
>
> V.
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to