How to avoid cyclic dependency?


I have two files:
b  = require 'b'
a = 
  func: ->
  otherFunc: ->
    # ...
module.exports = a
a = require 'a'
b =  
  func: ->
module.exports = b

And it doesn’t work. is called only from

Files are obviously more complex.

How should I solve it? I can put into one file, but it doesn’t look like real solution.


Probably this situation means that there is something in the application design that should be changed. Here you can find more information about dependency cycles.

Hope this helps!