-
Notifications
You must be signed in to change notification settings - Fork 20
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
Linear dependencies between imported modules become circular #65
Comments
Thank you so much for your empowering comments - I would greatly appreciate it if you do spread the word on social media! I will look into this over this week/weekend & come back to you with an answer! |
Thank you, |
If I understand right you issue is Circular Dependencies in AMD / CommonJs modules. Good news, I think:
*If you really want to have circular dependencies (most times its best to avoid them), *:
Now, if you DONT want to have circular dependency, I now realize that the There is no easy solution for this I fear, unless you a) can make a least one of them a standalone bundle ? But certainly this can be improved. or b) write a custom If you could please make a github repo with simplistic skeleton of you problem, I will take a closer look. Regards |
Sorry, I was unavailable for few weeks and then it took me some time to gather the different files to set up the repo. So, in my case I "DONT want to have circular dependency" so I wrote a resource-converter (it's the first time I tried, it's great !) So, here is the repository which highlights my structure and my problem: I also thought that a solution could be to enforce explicit |
Thanks so much for this feedback - I will check it out and get back to you, hopefully this weekend :-) |
@demurgos still havent looked at this, due to lack of time... but its in the pipeline & I will get back to you when I have some news :-) Thanks again |
At this point I don't think that this will be solved. I'll keep my demo repo up for some time but I plan to delete it and close this issue. Please fork it if you think that you might still need it. |
Yeah, so sorry but my time is limited these days and I have unfortunately abandoned the project :-( |
As a side note, circular dependencies are easily solved in CommonJS, if you use the given So, if instead of reassigning
you do a
then you will NOT have a problem with circular deps. This should also work on the AMD / UMD urequire conversion. Of course it doesn't work if you want to assign something other than an |
I've tested with https://github.com/Demurgos/urequire-imports-dependencies and it works like a charm - my tests on the repo are in a bad state and had no time to refactor them :-( Check the docs here https://github.com/anodynos/uRequire/blob/99c4370464fe0673fe488442ae6fc560ba132565/source/code/config/ResourceConverters.coffee.md#injectdeps |
Thank you for fixing this |
You're welcome @demurgos - there a better fix today with beta.31 - non-bundle dependencies (eg |
Hi,
First of all I would really thank you for this module: if I could star it 10 times, I would! It really saved me a lot of troubles when exporting some common components for node and the client.
I really like the possibility to import general purpose modules (Q, _, custom helpers, etc.) but I feel that I encountered an issue.
I wrote two modules
helper.js
&_Error.js
.The first one provides some general purpose functions independent of the platform, ie. I included an
inherits
function (similar to the one in Node'sutil
) so I can use it in the browser too.The second one extends the native
Error
to provide more constructors, add data to follow error causes easily in JS, provide easier error naming & output all these data nicely.Note that
_Error
extends the nativeError
withhelper.inherits(_Error, Error)
so it stays compatible with the test_error instanceof Error
._Error
requireshelper
.I expect to use these general purpose modules in my whole application so I would like to add both of these modules in my config:
The problem is that now,
helper
is required in_Error
(that's what I need) but_Error
is also required inhelper
(I don't really need that there, if there's really a problem I'll just use the nativeError
).Because both of these modules are imported, their "linear" relation is lost and I get circular dependencies. I cannot really force the order of the imports (I tried:
_Error
is evaluated beforehelper
, bad luck...) even if I try to explicitly addrequire("./helper")
in_Error
to enforce their relation.In this example, as in many other situations I guess, I could simply copy the code required during the creation of the object to avoid any relation between my modules but I feel there must be a better option.
In this example, I use just
helper.inherits
during the evaluation of_Error
, but if I think that dependencies between general purpose modules and libraries likeQ
or_
should work automagically like the rest of this module.I would like to thank you again for this fantastic module and hope that this example can help to improve it. ;)
The text was updated successfully, but these errors were encountered: