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

exports and node_modules inside package resolving broken #304

Closed
alexander-akait opened this issue Sep 17, 2021 · 4 comments · Fixed by #305
Closed

exports and node_modules inside package resolving broken #304

alexander-akait opened this issue Sep 17, 2021 · 4 comments · Fixed by #305

Comments

@alexander-akait
Copy link
Member

@alexander-akait I think you closed my issue prematurely, though granted it was a bit inaccurate.

I've done a bit more digging - the key difference between the node_modules folders that npm and yarn generate is that yarn creates node_module folders in each dep where their deps have cli tools with a nested .bin folder and npm does not.

So from the above, ipfs-unixfs-importer depends on rabin-wasm which has a cli tool.

With npm I get:

my-project/
├── node_modules/
│   ├── .bin/
│   │   └── rabin-wasm
.. other files
│   ├── ipfs-unixfs-importer/
|   |   └── package.json // etc

With yarn I get:

my-project/
├── node_modules/
│   ├── .bin/
│   │   └── rabin-wasm
.. other files
│   ├── ipfs-unixfs-importer/
│   │   ├── node_modules/
│   │   │   └── .bin/
│   │   │       └── rabin-wasm
|   |   └── package.json // etc

If I remove (or rename) the nested my-project/node_modules/ipfs-unixfs-importer/node_modules folder everything works, if I leave it, webpack does not resolve the rabin-wasm dependency. I guess it doesn't walk back up the tree to find the next node_modules folder if the first one doesn't have the dep it's looking for like node does?

You can see this yourself with the repro repo.

Originally posted by @achingbrain in webpack/webpack#14268 (comment)

@alexander-akait
Copy link
Member Author

@achingbrain we have a bug, somewhat critical

exports example:

"exports": {
    ".": {
      "browser": "./esm/src/index.js",
      "require": "./cjs/src/index.js",
      "import": "./esm/src/index.js"
    }
  }

Reproducible:

  • we have package node_modules/package-1 with node_modules and the exports field
  • we try to load package-2 inside node_modules/package-1/index.js
  • due ModulesInHierachicDirectoriesPlugin logic we try to search in node_modules/package-1/node_modules/package-2 , (using - request - ./package-2 and path - node_modules/package-1/node_modules)
  • package-2 doesn't exist
  • but because we apply ExportsFieldPlugin plugin we try to search in the exports field and ./package-2returnbrowser entry from theexports` field

@alexander-akait
Copy link
Member Author

Let's wait @sokra answer, fix is easy, we should skip resolving in ExportsFieldPlugin when we try to resolve file from ModulesInHierachicDirectoriesPlugin

@achingbrain
Copy link

I think this problem also exists for enahnced-resolve@4.x.x, is there any possibility a fix can be backported for those still using webpack 4 (e.g. react-scripts, etc)?

@alexander-akait
Copy link
Member Author

@achingbrain i am afraid v4 accept only security fixes, what is the blocker to update?

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

Successfully merging a pull request may close this issue.

2 participants