I have a rather large Backbone.js project that uses RequireJS. As the project size grew (\"size\" here referring to the number of separate module files), intermittent errors sta
I've been fighting with the same issue the last days and this is what I found out:
Apparently, a nested dependency structure requiring templates via the text.js plugin can cause a race condition that lets the top level module not be ready when requirejs thinks it is. I only ran into this problem when I had several nested module dependency structures of this type:
Router
-> View1
-> text!.../view1.html
-> View2
-> text!.../view2.html
-> View3
-> text!.../view3.html
-> View4
-> text!.../view4.html
-> View5
-> text!.../view5.html
-> View6
-> text!.../view6.html
-> View7
-> text!.../view7.html
-> View8
-> text!.../view8.html
Having this structure, I got TypeErrors like 'View1 is not a constructor' when the router tries to instantiate the views.
Also requiring the templates of the nested views in the top level views solved the problem for me:
Router
-> View1
-> text!.../view1.html
-> text!.../view2.html
-> View2
-> text!.../view2.html
-> View3
-> text!.../view3.html
-> text!.../view4.html
-> View4
-> text!.../view4.html
-> View5
-> text!.../view5.html
-> text!.../view6.html
-> View6
-> text!.../view6.html
-> View7
-> text!.../view7.html
-> text!.../view8.html
-> View8
-> text!.../view8.html
I don't really know how require.js works, but this looks to me like those nested text! calls aren't regarded when some 'ready' flag for the parent module is set.