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

moduleDirectories vs modulePaths #1268

Closed
1 of 4 tasks
andrewbaxter opened this issue Sep 21, 2022 · 5 comments
Closed
1 of 4 tasks

moduleDirectories vs modulePaths #1268

andrewbaxter opened this issue Sep 21, 2022 · 5 comments

Comments

@andrewbaxter
Copy link

andrewbaxter commented Sep 21, 2022

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?

Please Explain in Detail...

The descriptions for the two are not meaningfully different, in addition the link to NODE_PATH doesn't work and (assuming I found the current documentation) says roughly the same thing as the other two.

I looked at the code and AFAICT moduleDirectories identifies stopping directories when trying to find the package.json for a specific json file (i.e. it stops going up looking for further directories at that point). This surprises me because it seems to have nothing to do with the current description in the documentation, but somewhat explains why / is forbidden (it would also be helpful if the error message mentioned / explicitly since "name" does not always imply a single path segment).

Having read the code, I'd guess that if you specify a/b/c as a modulePaths element, moduleDirectories should include c for the same reason it by default includes node_modules.

@eliot-akira
Copy link

eliot-akira commented Oct 3, 2022

I was also confused by the difference between moduleDirectories and modulePaths.

I had a working setup with @rollup/plugin-node-resolve version 14.0.1, which broke on version 14.1.0 with the following error.

Error: `moduleDirectories` option must only contain directory names. If you want to load modules from somewhere not supported by the default module resolution algorithm, see `modulePaths`.

The error message is confusing too - perhaps it should link to the docs for these two options.

Apparently modulePaths is for absolute paths (/a/b/c), and moduleDirectories is for matching single directory name (c) regardless of where it is.

@davidhellmann
Copy link

Same error here.
My config looks like this:

...
nodeResolve({
  moduleDirectories: [path.resolve('./node_modules')],
}),

works until I update to the latest version.

@stale stale bot added the x⁷ ⋅ stale label Dec 16, 2022
@stale
Copy link

stale bot commented Dec 20, 2022

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

@stale stale bot closed this as completed Dec 20, 2022
@jorenbroekema
Copy link
Contributor

Yeah this was quite confusing to me as well. Seems like I could just drop-in replace moduleDirectories with modulePaths, but is very unclear on what the difference is exactly and when to use what.

@jorenbroekema
Copy link
Contributor

#1104 (review) here's a bit more info, I believe it was completely missed in this PR that this change was a breaking change. Users of this plugin may have relied on moduleDirectories being paths with '/'s, I certainly did, so breaking that by throwing an error and forcing users to use the new option is definitely a breaking change.

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

No branches or pull requests

4 participants