resolve: doesn't support `$HOME/.node_modules` or `$HOME/.node_libraries`

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (16 by maintainers)

Commits related to this issue

Most upvoted comments

The current workaround for this is to pass [$HOME/.node_libraries, $HOME/.node_modules] as the paths option.

However, what I can provide, is to say I didn’t write anything about NODE_PATHS in the example repo. Also git grep -nFe NODE_PATH came back empty, so it hasn’t crept in.

is there any way to repro it on the command line?

Yes, if you run demo.sh in an environment similar enough to the GitHub Actions env.

readlink: illegal option -- m

You’ll need GNU coreutils 8.21 or later installed. Ubuntu ships it by default, so I use that in the GitHub Actions.

Try setting preserveSymlinks: false explicitly (or try a resolve 2 prerelease).

Done in the no-preserve-symlinks branch, results are in.

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 '.'
[…]