inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.29k stars 716 forks source link

Require cycle #1301

Open t-ricci-enhancers opened 3 years ago

t-ricci-enhancers commented 3 years ago

Using inversify v5.0.5 and metro-bundler (running on react-native with babel) I get this warning.

[Fri Mar 19 2021 20:58:19.746]  WARN     Require cycle: node_modules/inversify/lib/syntax/binding_on_syntax.js -> node_modules/inversify/lib/syntax/binding_when_syntax.js -> node_modules/inversify/lib/syntax/binding_on_syntax.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.

Can something be done to avoid having to do that require cycle?

notaphplover commented 3 years ago

Hi @t-ricci-enhancers, we could avoid that warning mixing binding_on_syntax module and binding_when_syntax in the same module, but we prefer to keep modules with only one class, so I wonder if it's a good idea.

I don't like the idea of having circular dependencies even if it's safe in this specific case.

linonetwo commented 1 year ago

When build a project that imports inversifyjs

(!) Circular dependencies
../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/inversify.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/container/container.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/resolution/resolver.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/scope/scope.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/inversify.js
../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/inversify.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/container/container.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/resolution/resolver.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/utils/binding_utils.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/inversify.js
../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/syntax/binding_on_syntax.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/syntax/binding_when_syntax.js -> ../../node_modules/.pnpm/inversify@6.0.1/node_modules/inversify/es/syntax/binding_on_syntax.js

will this cause any problem?