webpack: Dependency resolution of 3rd-party imports fails

Bug report

What is the current behavior?

yarn run build in my MWE (note the commit hash in the URL fails with a bunch of resolver errors.

If the current behavior is a bug, please provide the steps to reproduce.

  1. git clone https://github.com/johnrichardrinehart/wouter
  2. git checkout 7d6938c83a311f3e35db55f271e4724822f5e6dc
  3. yarn run build

What is the expected behavior?

yarn run build should bundle all my assets and stick them in ./dist/.

Other relevant information: webpack version: 5.9.0 Node.js version: node v15.3.0 Operating System: Ubuntu 20.10 Additional tools: yarn v2.40.0 (berry, so yarn set version berry)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 36 (16 by maintainers)

Commits related to this issue

Most upvoted comments

So far I think it’s a webpack (enhanced-resolve) bug regarding removing fullySpecified when resolving module request with PnP, but I have to investigate further…

  • wouter looks fine
    • peerDependenciesMeta is not needed, peerDependencies is enough. Without that you would get another error telling that it is missing.
    • import "react" is valid when using type: "module"

One extra tidbit:

No problems with webpack here, yarn can’t resolve it, run it in Node.js and you will get the same problem

The Node resolver doesn’t support ESM yet (tracked here), so the test you made crashes in Node because of that, but in the case of Webpack it shouldn’t matter because you only use requireToUnqualified, which only resolves bare identifiers (wouter) to the package location on the disk. The rest of the resolution (indexes, modules, etc) should be handled by Webpack, and thus work 🤔

@johnrichardrinehart anyway feel free to feedback or post the solution, it may help other developers in future, if you get stuck with this for a long time, you can ping me again, maybe I will have time and help you