Knockout-to-Demand Mapping Plugin: Crash Thrower: Inconsistent anonymous define () method

I got this problem using knockout.mapping plugin combined with RequireJS. Basically, the site that hosts my application loads knockout, knockout.mapping and requirejs in that order.

<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>


Without doing anything further, I get this mismatch error. Is there some order that I don't understand?

/// Update ///

I wrote these two tests:

Basically, you can see that if I load require.js in my project on my own, before the mapping plugin, then the mapping plugin becomes invisible. I guess it has to do with how to use the conversion plugin, requiring it to require a knockout ... but I can't duck why it fails.

/// 2nd Update ///

The script seems to be important here, so I'm going to provide a little more context.

Draw a web app that defines knockout.js and knockout.mapping.js in script tags. The third party widget is then loaded into a page that uses requireJS to install dependencies. This is the problem that appears to be causing the problem. Since some libraries were loaded through the old school, manual way and others were loaded using require, require seems to be in conflict with the context of existing libraries.

If I remove the link required from the host application, I get an error when I go back to see if ko.mapping exists. This is obviously due to the widget requiring a knockout which somehow broke it with display plagiarism.

I think I need someone who is very familiar with RequireJS to comment on these libraries. Obviously, when I create a widget for anonymous consumption, I won't know how or if consumers are using requireJS.

/// 3rd Update /// Trying to figure out the problem as best as possible, maybe this would make more sense:

Is there a well-defined template where you could add a widget that uses RequireJS to an existing web page that manually loads resources? It would seem impossible, since RequireJS just doubles the load on whatever the traditional page has already loaded.


source to share

1 answer

The answer is to load all of your Java scripts with a module loader and not look back. I seriously think this is the only solution. Developing a widget that uses a module loader in a world where most client sites haven't gotten to this point yet, still forces you to use some old school mentality.

Now if I could just get +50 points, I was pissed at this question :)



All Articles