symlink require issue: require only looks in the symlinked parent folder eventhough it has access to the working folder #4757

Closed
dotnetCarpenter opened this Issue Feb 12, 2013 · 2 comments

Projects

None yet

2 participants

@dotnetCarpenter

Issue: When using npm link for developing packages, require doesn't look in node_modules in the working directory but only in the symlinked directory. As you can see in the variable dump below, the path to the working directory is present (in parent.parent) but require doesn't look there.

Environment: node v0.8.19, npm 1.2.10, OS X: 10.7.5

Debugging:
My working directory is npm-image-list/ and it uses a module from npm-detectionizr/ which is a directory sitting next to it, in the folder hierarchic.
Here is a dump of the parent variable on line 276 in module.js:

{ id: '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-detectionizr/lib/d... (length: 88)',
  filename: '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-detectionizr/lib/d... (length: 88)',
  loaded: false,
  paths: 
   [ '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-detectionizr/lib/n... (length: 91)',
     '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-detectionizr/node_... (length: 87)',
     '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/node_modules',
     '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/node_modules',
     '/Volumes/Macintosh HD 2 1/dotnetCarpenter/node_modules',
     '/Volumes/Macintosh HD 2 1/node_modules',
     '/Volumes/node_modules',
     '/node_modules' ],
  parent: 
   { id: '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-image-list/lib/ima... (length: 89)',
     filename: '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-image-list/lib/ima... (length: 89)',
     loaded: false,
     paths: 
      [ '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-image-list/lib/nod... (length: 89)',
        '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/npm-image-list/node_mo... (length: 85)',
        '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/server/node_modules',
        '/Volumes/Macintosh HD 2 1/dotnetCarpenter/Projects/node_modules',
        '/Volumes/Macintosh HD 2 1/dotnetCarpenter/node_modules',
        '/Volumes/Macintosh HD 2 1/node_modules',
        '/Volumes/node_modules',
        '/node_modules' ],

My module in tries to load modules in the working directory and echoes back the result. This works if the module is installed and not symlinked. But I can imagine that I'm not the only one who would want to symlink node_modules and still be able to use a module like my detectionizr - shameless plug 👯

I found an old pull request, that might handle this: https://github.com/joyent/node/pull/2599/files but I can't build node with my current Volume label setup (I tried to change label but OSX doesn't like - thrust me).

Is it worth a fix?

@isaacs

This would be a semantic change to how the module loader works. The current behavior is that symlink modules look for modules relative to their realpath'ed locations. No thanks, we're not going to change it.

@isaacs isaacs closed this Feb 12, 2013
@dotnetCarpenter

I understand your rationale. But why keep a reference to "virtual" paths via parent.parent.paths? Can I tell node what behavior I want, e.i. look at parent.parent.paths and not parent.paths?

Thank you for your time and congratulation with your 4 year old.

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