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

modules in node_modules not resolved when using lookupStartPath "."? #231

Open
sverweij opened this issue Jul 15, 2020 · 5 comments
Open

Comments

@sverweij
Copy link
Contributor

sverweij commented Jul 15, 2020

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: bcf7ee8) against node 14, 12 and 10
  • [email protected] from npm against node 14

(both on OSX 10.15.5)

@sokra
Copy link
Member

sokra commented Jul 16, 2020

It has to be an absolute path. The readme always uses an absolute path at that location too.

@alexander-akait
Copy link
Member

@sokra I think we can fix it for better DX

@sokra
Copy link
Member

sokra commented Jul 16, 2020

This is very performance sensitive...

@sverweij
Copy link
Contributor Author

@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?

@alexander-akait
Copy link
Member

@sverweij yes, it is good to document it, you can send a PR to docs with this note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants