-
Notifications
You must be signed in to change notification settings - Fork 290
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
Is it legal to modify module.paths
?
#2711
Comments
I don't think it's good/worth to change it even though the docs don't explicitly prohibit it, you can see relevant docs at modules#loading_from_the_global_folders which has a similar idea. What is your use case? Why isn't it possible to just explicitly specify a path to the module? |
@lundibundi I think it is extremely important to explicitly state (im)mutability of such basic APIs. This will make a clear border between illegal (with possible undefined behavior) and legal but possibly rare usages (with fully defined behavior). |
Well, the original property was added more than 9 years ago (nodejs/node@4651348) and was undocumented up until 3 years ago nodejs/node#14435.
Yeah, if that was an API added now it would definitely be better documented and stated its mutability but at this point it more of an it-was-there-from-the-beginning and it not gonna go away so at least document it. From that point in time, a lot has changed especially since we "Node.js ecosystem has settled on a convention for locating dependent modules". The part of the doc on global folders somewhat touches current concerns/state of it. So to sum it up, yes it is public documented API so you can use it (including changing) but whether you should is whole another question. My personal answer would be 'no unless you are absolutely sure you need it'. |
answered, closing. feel free to re-open if it is outstanding |
I have a nested project and I've noticed that if the outer project's node_modules is present, the inner project will not build or run. This appears to have to do with module resolution issues.I'm using storybook in a project, which depends on `@mdx-js/[email protected]`, while the child folder is docusaurus and depends on `@mdx-js/[email protected]`.
One of my dependencies is importing this (I don't have an explicit import anywhere) so I can't force the resolution path. And I'm stumped why it chooses the parent folder version anyway; maybe something was digging around for a specific symbol?) Therefore, I wish to strike the parent project's node_modules from Should this be reopened? Is there a better API to make node submodule projects resolve their own modules all the time, even if that means giving up on a resolution/import? Am I wrong in thinking that import paths should be configurable enough to nest projects? Edited to add: changing module.paths in the entrypoint js file does not fix the problem, though it does affect what I can import in the REPL. I guess there's a routine that populates |
No, that’s not a thing that should be easily possible. |
v.13.12.0
Windows 7
Runtime/docs.
module.paths
.Docs are not very helpful, since they do not clarify is this property mutable or not.
It is important, because changing this variable actually leads to changes in the behavior of
require
function.So it would be good if someone make it clear what kind of usage this property supports and intended to.
Basically, the following code works just fine:
But should it work at all?
It hard to say from the docs.
Please, advise. Thanks.
The text was updated successfully, but these errors were encountered: