7
votes

I'm following the multipage shim sharing pattern here: https://github.com/requirejs/example-multipage-shim

I'm using the same common.js and have a very similar and simple set up:

<script src="js/library/requirejs/require.min.js"></script>
<script>
require(['./js/config/common'], function (common) {
  //go on...
});
</script>

Everything loads fine and I can continue running operations inside the require closure, but I keep getting an error in Firefox complaining about a mismatched anonymous define() module with the above code. Given how simple it is and that I'm following the example pattern pretty much exactly I'm a bit confused as to why I'm getting it. I haven't used define() anywhere. Has something in requireJS changed in the last 24 days (since the multipage git repo was updated)?

2
Is there a self-contained JSFiddle you can post which illustrates the issue? You say it's "pretty much exactly" like the example, but how exactly is "pretty much" :-)explunit
I'm working on a huge platform unfortunately, if I piece apart what I've done above in to jsfiddle it works fine. So leads me to believe there might be an issue or conflict with something else on the page. One strage note though -- if just place an empty define(function(){}) in common.js the error is not thrown, as soon as I reference requirejs.config() (even without args), I get the error...Dan
OK, I believe the problem is the same as one the one here, stackoverflow.com/questions/15371918/…, in that the problem happens when I use requirejs in an anonymous module definition. The docs say that this is an issue when not using the optimizer, and says use the optimizer to fix it. Question is -- how exactly are we supposed to get around it while doing development, i.e. working in an unoptimized environment??Dan
More weird stuff, if I put an alert() before the //go on... line above the error doesn't occur.Dan

2 Answers

7
votes

Answer was this, hopefully it helps someone:

Given this was a big platform, lots of other stuff was being loaded outside of the require flow (we're slowly transitioning).

Some of these assets, i.e. jquery 1.10, spin.js, etc., were compatible with AMD, and were calling define(). In the spin.js case, it was calling define() anonymously, which was tripping up the loading as is explained in the second point of the Mismatched Anonymous error in the resolve docs.

Good grief.

0
votes

It is clear what is going on. You are trying to load module, but your common.js has only require.config and there is no module. Therefore updated RequireJS (not Firefox) throws an error. Include define in your common JS and error should go away.

// common.js stuff...
define({});