1

Yes, I know this has been asked ad infinitum here, and I already know the general rule that when using requirejs, everything that calls define() must be loaded through a single script tag as in:

<script src="js/lib/require.js" data-main="js/main"></script>

but I find myself in a position where the general advice offered with respect to this common error is not sufficient for solving my particular problem, which on the surface seems pretty simple.

I am working on an angular, requirejs, and WinJS (just to keep things interesting) app, and have run into a problem with this error. My main html file does indeed load several other JavaScript source files using separate script tags but none of them call define(). I checked. Twice. Okay, three times. All other JS source files in the app are loaded through a single script tag similar to the above. Yet I still get this error.

I tried giving each of my app modules a requirejs identifier:

define('myModule', ['dep1', 'dep2', etc.], function(dep1, dep2) {
    return angular.module('app.mymod', ['winjs', etc.]);
});

but with this approach angular modules that depend on the angular module defined as above cannot resolve that dependency (although requirejs is now perfectly happy).

The three JS files being loaded outside requirejs are:

<script src="//Microsoft.WinJS.2.0/js/base.js"></script>
<script src="//Microsoft.WinJS.2.0/js/ui.js"></script>
<script src="js/lib/dynamic-content-shim.js"></script>

Where the latter patches the WinJS runtime to allow dynamic content creation. The WinJS runtime does actually expose a define function in its own namespace, but it is completely unrelated to requirejs.

So what gives?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
lje
  • 413
  • 5
  • 16
  • Some of the causes of the error you are getting are listed [here](http://requirejs.org/docs/errors.html#mismatch). However, I do not think that the list there is exhaustive. At any rate, there is not enough information in your question to make an informed guess as to the cause of the error that *you* get. – Louis Mar 16 '15 at 10:26
  • Mixing Angular and Require is strange... I have done some effort [here](https://github.com/nikospara/angular-require-lazy), if it proves useful in any way. But I agree with Louis, you probably have to include more details (and there are lots of them). – Nikos Paraskevopoulos Mar 16 '15 at 12:10
  • Thanks folks for your input. I've read that section of the requirejs website a couple of dozen times. None of it applies to my situation. And if there were any more info to add I would, but you would be utterly bored with the details. There is nothing fancy going on here. A couple of modules dependent on a couple other modules. Nothing near as fancy as what you've done @NikosParaskevopoulos, But you link may prove useful for something I want to try later. Thanks. – lje Mar 17 '15 at 03:21

0 Answers0