Circular dependencies in ES6 / 7

I was surprised to find that in Babylon I can have two import modules with each other without any problems. I have found several places that refer to this as a well-known and expected behavior in Babylon. I know this is widely considered an anti-pattern by many (I guess most) people, but please ignore this for this question:

Does anyone know if this (or will) be the correct behavior in ES6 / 7?

The closest thing I can find in the official answer (and technical explanation) is this comment on 2ality.com

+6
source share
2 answers

This is usually considered a bad experience. But ES modules are designed to support circular dependencies. There is some information in the ES 2017 specification 15.2.1.16.3 ResolveExport Concrete Method . However, it seems to me that it is very difficult to read (to be honest, I suffer a lot). The message you mentioned on 2ality.com may be more readable.

+5
source

I work with nodeJS, so this is the same. From what I know, โ€œrequired cyclesโ€ are not illegal, even if they are often best avoided. If there is a loop, nodeJS will at least handle this: it will not require a second time.

+1
source

Source: https://habr.com/ru/post/1011971/


All Articles