-
Notifications
You must be signed in to change notification settings - Fork 318
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
Madge cannot find dependency if required via for loop #115
Comments
Thanks for reporting! Seems like a runtime analysis is necessary to determine the modules being required, which is beyond the reach of what dependency-tree (and static analysis) can do. I don't think we can do much here without building fragile and specific sniffs to fake runtime execution, but curious to hear thoughts from others. |
I agree with @mrjoelkemp. I don't see any way to fix this without a introducing a lot of complexity and possible bugs. So I'm closing this for now. But if anyone has a brilliant solution to this I'm very happy to discuss it :) |
@dustyhorizon what is your use case for this? Typically when we require something, we want to assign it to a variable so we can use it. In the example code you provide, each item required must have some side effect (like introducing or modifying global variables) to do anything useful, right? So I'm not sure what you're trying to accomplish, but maybe the following will help. If 'configs' is something like this: module.exports = ['config1', 'config2', ...] Maybe you could refactor it to something like this: module.exports = [require('config1'), require('config2'), ...] Then you can just let files = require('configs') And you should get a nice dependency graph. |
I have a list of 'modules' (in either enabled or disabled state) in a 'config' file (exported as an object) in which the loader will iterate and require each item under the enabled key. My first project in nodejs so not very good at optimizing and refactoring it yet haha. |
Hello,
I have a code where I read from file and require from a for loop. This does not display any dependant module in the resultant graph.
E.g.
Any possible fix?
The text was updated successfully, but these errors were encountered: