enhanced-resolve
enhanced-resolve copied to clipboard
modules in node_modules not resolved when using lookupStartPath "."?
It looks as though attempts to resolve external modules got jammed somewhere. Did I forget something? Should I pass something extra? Is it a deliberate deprecation?
Steps taken
Run the example from the README:
sample.js
const resolve = require("enhanced-resolve");
console.log(
resolve.sync(".", "enhanced-resolve")
);
Expected
The resolved file path (something like ./node_modules/enhanced-resolve/lib/node.js) is printed to stdout.
Found
An error is thrown:
/Users/lalala/thing/node_modules/enhanced-resolve/lib/pathUtils.js:39
switch (p.length) {
^
TypeError: Cannot read property 'length' of undefined
at getType (/Users/lalala/thing/node_modules/enhanced-resolve/lib/pathUtils.js:39:12)
at join (/Users/lalala/thing/node_modules/enhanced-resolve/lib/pathUtils.js:145:10)
at cachedJoin (/Users/lalala/thing/node_modules/enhanced-resolve/lib/pathUtils.js:181:15)
at Resolver.join (/Users/lalala/thing/node_modules/enhanced-resolve/lib/Resolver.js:449:10)
at /Users/lalala/thing/node_modules/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.js:40:50
at Array.map (<anonymous>)
at /Users/lalala/thing/node_modules/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.js:40:32
at Array.map (<anonymous>)
at /Users/lalala/thing/node_modules/enhanced-resolve/lib/ModulesInHierachicDirectoriesPlugin.js:39:14
at _next0 (eval at create (/Users/lalala/thing/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:8:1)
Notes
- resolution of local paths works as expected (so filling out './sample' instead of 'enhanced-resolve' correctly yields 'sample.js'
- passing
process.cwd()
instead of"."
does resolve to the correct file in node_modules. - passing an explicit modules array to the options -> same error thrown
- tried the same with the create resolver and the async samples in the readme (with the same results)
The same code works as expected in enhanced-resolve@latest (currently 4.3.0)
Environment
- webpack
webpack/enhanced-resolve#master
(commit hash: bcf7ee84) against node 14, 12 and 10 - [email protected] from npm against node 14
(both on OSX 10.15.5)
It has to be an absolute path. The readme always uses an absolute path at that location too.
@sokra I think we can fix it for better DX
This is very performance sensitive...
@sokra gotcha, clear!
Even though v4 wasn't supposed to be able to receive relative paths in lookupStartPath, for ppl migrating from v4 -> v5 it might be unexpected. Should this be documented as a breaking change in i.e. final release notes for v5?
@sverweij yes, it is good to document it, you can send a PR to docs with this note.