You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doesn't support $HOME/.node_modules or $HOME/.node_libraries #163
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.
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.
It seems resolve searches for modules in module directories inside of module search path directories, but not inside the module search path directories themselves.
@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.
@mk-pmb thanks - is there any way to repro it on the command line? When i run npm test I get:
> [email protected] test
> bash demo.sh
readlink: illegal option -- m
usage: readlink [-n] [file ...]
demo.sh: line 11: cd: /prepare: No such file or directory
The first two tests are the part that had been easy to fix ever since. The bug in my opening post is reproduced in the 3rd test case, and it still fails:
In other words, this issue has nothing to do with symlinks - it's about some kind of special $HOME/.node_modules path that nobody's ever mentioned in a decade of this package not supporting it :-) I'll update the title to reflect that.
(note that "global" means npm root -g; this home dir thing is something else)
Fix the naming of the module to be resolved via ~/.node_modules
Add test for ~/.node_libraries
Add test for an actual global module
Update: Today I learned that my global modules being require()-able system-wide is just accidential. The node design concept seems to understand npm --global as related only to modules' CLI commands, not the modules themselves.
Activity
ljharb commentedon Jun 2, 2018
I think you'll need to set the
preserveSymlinksoption totrue.mk-pmb commentedon Jun 3, 2018
Nope, doesn't seem to help:
mk-pmb commentedon Jun 3, 2018
To clarify, with "explicitly resolve the returned path" I meant I have to
fs.realpath()it myself.ljharb commentedon Jun 17, 2018
(Possibly related to #122)
safizn commentedon 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 commentedon Aug 26, 2018
@myuseringithub does node itself work with windows symlinks?
mk-pmb commentedon 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:
It seems
resolvesearches for modules in module directories inside of module search path directories, but not inside the module search path directories themselves.safizn commentedon 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-symlinkis set to false by default.ljharb commentedon Jan 3, 2022
I'm unclear on what needs to be done here. Could anyone provide a repro repo, or better, a failing test case?
mk-pmb commentedon Jan 9, 2022
Bug demo in GitLab Actions: https://github.com/mk-pmb/browserify-resolve-symlink-163
ljharb commentedon Jan 11, 2022
@mk-pmb thanks - is there any way to repro it on the command line? When i run
npm testI get:ljharb commentedon Jan 11, 2022
@mk-pmb ah! resolve 1 has
preserveSymlinks: trueset by default. resolve 2 haspreserveSymlinks: falseset by default.Try setting
preserveSymlinks: falseexplicitly (or try a resolve 2 prerelease).mk-pmb commentedon Jan 11, 2022
Yes, if you run
demo.shin an environment similar enough to the GitHub Actions env.You'll need GNU coreutils 8.21 or later installed. Ubuntu ships it by default, so I use that in the GitHub Actions.
Done in the
no-preserve-symlinksbranch, results are in.ljharb commentedon Jan 11, 2022
Seems like it's good! Does that mean this can be closed?
mk-pmb commentedon Jan 11, 2022
The first two tests are the part that had been easy to fix ever since. The bug in my opening post is reproduced in the 3rd test case, and it still fails:
8 remaining items
ljharb commentedon Jan 15, 2022
whoa, that was not a thing I was aware of.
resolvehas no knowledge of those paths and isn't set up to use them, and I'm not sure why anybody else would.$HOMEshouldn't have any node_modules.ljharb commentedon Jan 15, 2022
In other words, this issue has nothing to do with symlinks - it's about some kind of special
$HOME/.node_modulespath that nobody's ever mentioned in a decade of this package not supporting it :-) I'll update the title to reflect that.(note that "global" means
npm root -g; this home dir thing is something else)[-]Doesn't find modules behind symlinks?[/-][+]doesn't support `$HOME/.node_modules`[/+]ljharb commentedon Jan 15, 2022
For history's sake: nodejs/node@5a49f96#diff-cdd77182e73349d6c83fbbce1cccf6f15972fbece4dbd9c52eececf1ca3bfcd5R307-R308 is in every node version since basically ever.
[-]doesn't support `$HOME/.node_modules`[/-][+]doesn't support `$HOME/.node_modules` or `$HOME/.node_libraries`[/+]mk-pmb commentedon Jan 16, 2022
I updated my test project;
~/.node_modules~/.node_librariesAdd test for an actual global moduleUpdate: Today I learned that my global modules being require()-able system-wide is just accidential. The node design concept seems to understand
npm --globalas related only to modules' CLI commands, not the modules themselves.ljharb commentedon Jan 16, 2022
indeed; global things aren’t supposed to be requireable.
ljharb commentedon Jan 18, 2022
The current workaround for this is to pass
[$HOME/.node_libraries, $HOME/.node_modules]as thepathsoption.[New] add default support for `paths` to include `$HOME/.node_{module…
ljharb commentedon Jan 21, 2022
@mk-pmb can you confirm that #273 works for you? (or the equivalent change on 1.x)
[New] add default support for `paths` to include `$HOME/.node_{module…
[New] add default support for `paths` to include `$HOME/.node_{module…
[New] add default support for `paths` to include `$HOME/.node_{module…
[New] add default support for `paths` to include `$HOME/.node_{module…