Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't find modules behind symlinks? #163

Open
mk-pmb opened this issue Jun 2, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@mk-pmb
Copy link

commented Jun 2, 2018

Hi, thanks for this module!
It seems to have trouble finding my packages, though:

$ readlink -m ~/.node_modules
/mnt/…/nodejs/modules
$ nodejs -e 'console.log(require.resolve("lodash")); require("resolve")("lodash", console.log);'
/mnt/…/nodejs/modules/lodash/lodash.js
{ Error: Cannot find module 'lodash' from '.'
    at /mnt/…/nodejs/modules/resolve/lib/async.js:50:31
    at processDirs (/mnt/…/nodejs/modules/resolve/lib/async.js:184:39)
    at ondir (/mnt/…/nodejs/modules/resolve/lib/async.js:199:13)
    at load (/mnt/…/nodejs/modules/resolve/lib/async.js:82:43)
    at onex (/mnt/…/nodejs/modules/resolve/lib/async.js:107:17)
    at /mnt/…/nodejs/modules/resolve/lib/async.js:12:69
    at FSReqWrap.oncomplete (fs.js:152:21) code: 'MODULE_NOT_FOUND' }

So require.resolve was able to find it, but resolve wasn't. However, it works when I create a symlink /mnt/…/nodejs/node_modules to modules.

Update: Work-around: It also works when I pass option { paths: [process.env.HOME + "/.node_modules"] }
Update 2: However, in that case I have to then explicitly resolve the returned path in order to get the exact same result.

@ljharb

This comment has been minimized.

Copy link
Member

commented Jun 2, 2018

I think you'll need to set the preserveSymlinks option to true.

@mk-pmb

This comment has been minimized.

Copy link
Author

commented Jun 3, 2018

Nope, doesn't seem to help:

$ nodejs -e 'console.log(require.resolve("lodash")); require("resolve")("lodash", { preserveSymlinks: true }, console.log);' 
/mnt/…/nodejs/modules/lodash/lodash.js
{ Error: Cannot find module 'lodash' from '.'
[…]
@mk-pmb

This comment has been minimized.

Copy link
Author

commented Jun 3, 2018

To clarify, with "explicitly resolve the returned path" I meant I have to fs.realpath() it myself.

@ljharb

This comment has been minimized.

Copy link
Member

commented Jun 17, 2018

(Possibly related to #122)

@myuseringithub

This comment has been minimized.

Copy link

commented Aug 26, 2018

preserveSymlinks doesn't seem to work on Windows Symbolic link or Junction. Is there a problem with the implementation in the module ?
It never resolves to the real path, which what I needed from this module anyway. But the options preserveSymlinks: false, should work.
There seems to be a bug.

@ljharb

This comment has been minimized.

Copy link
Member

commented Aug 26, 2018

@myuseringithub does node itself work with windows symlinks?

@mk-pmb

This comment has been minimized.

Copy link
Author

commented Aug 26, 2018

I reproduced the problem and took an strace capture. The diff shows what really happened vs. what I'd expect to happen:

-stat64("/mnt/…/nodejs/modules/node_modules/lodash/package.json", …
+stat64("/mnt/…/nodejs/modules/lodash/package.json", …
 stat64("/mnt/…/nodejs/node_modules/lodash/package.json", …
 stat64("/mnt/…/node_modules/lodash/package.json", …
 stat64("/mnt/node_modules/lodash/package.json", …
 stat64("/node_modules/lodash/package.json", …

It seems resolve searches for modules in module directories inside of module search path directories, but not inside the module search path directories themselves.

@myuseringithub

This comment has been minimized.

Copy link

commented Aug 27, 2018

@ljharb Yes, I use symbolic link of type Junction, as it allows me to create symlinks that are supported between the host machine (Windows OS), and the Docker container (Linux OS) which I'm running the app on. In my setup both the host machine and container use JS scripts to run the project.
Node's require.resolve('<a symlink>') returns the real path of the symlink as Node's command option --reserve-symlink is set to false by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.