This is definitely a bug that I have encountered a lot over the last few days. Loading one module can cause a second completely unrelated module in a different part of the app to become undefined where it worked perfectly before. I have used RequireJS a lot - this is not a script loading or circular dependency issue. At first I encountered the error most often when requiring a text file in a 2nd-tier view that gets iterated quite a few times (1800+):
domReady -calls-> new View1() -iterates-> new SubView() -depends-> text!template
-calls-> new View2() --> undefined!
This would cause a completely unrelated module elsewhere to become undefined. I worked around it for a while by integrating the SubView functionality into the View module.
domReady -calls-> new CombinedView1() -depends-> text!template
-calls-> new View2() --> ... all good ...
As the project has grown I have hit the wall again and really need to find a way to fix it. Including more modules causes previously defined ones to become undefined at random. Require throws no errors and neither does the browser. I'm not using CoffeeScript or anything like that either.
I have taken some time create a version of my application that has the same module and dependency structure with the dependent Views, Models and Collections stubbed out. This works perfectly fine, so I can only assume there is some kind of memory issue? However Chrome never throws any errors either.
I think my next step will be to pad out my skeleton application with some memory-consuming loops and see what happens: I will let you know how it goes.
Using Require v2.0.1, so no order plugin - dependencies and packages are all configured using the shim config directive.
Non-AMD modules loaded:
- Backbone
- Underscore
- jQuery
- Mustache
- Leaflet
- Bootstrap
P.S. Apologies if this is not in the right place. I thought it would be better as a comment but I honestly can't see the comment button anywhere.
Update:
This dependency structure breaks consistently:
Main
- View 1
- text!...
- View 2
- text!...
Substituting the text with empty strings works fine every time:
Main
- View 1
- View 2
So why does waiting for the text to load cause View 1 to become undefined when it is explicitly set as a dependency in the Main module? Surely Main should not be called until everything it is dependent on is loaded?