Repository navigation
Does the require.resolve paths option work just like the baseDir option? #188
Description
Activity
Since it's relatively new, this package hasn't adapted to it yet, no.
Would you be willing to make a PR with test cases, comparing require.resolve's paths option to the basedir option?
Another possibility might be, adding a
pathsoption toresolveitself.(do you need the GLOBAL_FOLDERS? requiring things from there is widely considered an antipattern)
I don't mind taking a stab at it.
I don't personally use
GLOBAL_FOLDERSno, but I'm the maintainer of a popular module which is used to patch therequirefunction where I depend on being able to resolve modules. And I can't rule out if any of their apps depend on theGLOBAL_FOLDERSenvironment variable unfortunately.I somehow can't get the normal test suite to run in
master. Is it because I have cloned this repo into a folder whos path already contain anode_modulesfolder? Usually that's where I keep my all the Node modules I'm working on which makes working on multiple modules with inter-dependencies much easier.Installed in
/tmpand it worked. So I guess it's related to thenode_modulesfolder in the pathAs far as I can see, no where in the current tests do you validate that
require.syncreturns the same result asrequire.resolve. Is this on purpose?Not that I know of; I've always found that a bit confusing but haven't taken the time to fix it.
It sounds like there's a few action items here:
- file an issue about the repo not working properly with a sibling
node_modules(if i've understood the problem correctly) - make a PR that adds a test suite comparing both
resolveandresolve.syncwithrequire.resolve, to ensure consistency and/or illustrate the differences - make a PR for adding the
pathsoption
Thoughts?
- file an issue about the repo not working properly with a sibling
resolvedefinitely does not mimicrequire.resolvebehavior in terms ofpathsoption. Inrequire.resolveit works as multiplebasedir. But also require includes there dirs fromNODE_PATHwhich is rarely desired behavior.@watson are you interested in doing any of the steps I outlined above?
I've added bullet point 2 in 067db38.
If you could give me some examples of test cases for
pathswith more than one item, i can look into supporting it inresolve.- added a commit that references this issue
on Jan 21, 2022 I found a Node.js potential regression starts from Node 12.

Since Node.js v8.9.0, a new
pathsoption was made available to the core Node.jsrequire.resolvefunction:As far as I can see, if just given a single element in the
pathsarray, this works identical to thebaseDiroption of this module. The newpathsfeatures does however take into account theGLOBAL_FOLDERS, which I'm not sure if this module does?I ask because I would like to feature detect this and use the internal Node.js function if available, but fall back to this module if not. But I wasn't sure if the behavior was 100% identical 🤔