RequireJS Error: Mismatched Anonymous Define() Module

  • Updated

Templates with scripts that leverage RequireJS code and were working prior to upgrading to 9.0 now show an error in the console of MISMATCHED ANONYMOUS DEFINE() MODULES when the UXToolbar is enabled. 

 

Fixes to the product were made to workaround these changes in version 9.1 SP2 CU16. 

Site Updates
Ektron Version 9.10 SP2, Site Update 18 (EkSiteUpdate910184SP2018)

Update 16 (February 5, 2016)

23639 - If you used a JQuery version that did not match the version used in Ektron, there might be compatibility conflicts. (References to Ektron JQuery were renamed to not conflict and ensure compatibility.)

If you run into issues, please upgrade. If you cannot, please continue reading.

 The error message is thrown if a developer defines a module by adding an HTML script tag to a page. Here is an example of this issue: 

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>         <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="UX/vendor/requirejs/require.min.js"></script>         <script type="text/javascript" src="foo.js"></script>
    </div>
    </form>
</body>
</html>

function test (doDefine){
    if (doDefine) {
        define([], function () { });
    } else {
        window.foo = function () { };
    }
}

$(function () {
    if ('undefined' !== typeof (define)) {   
        alert("there is a define");
        test(true);
    }
    else {
        alert("There is no define");
        test(false);
    }
})

If you insert this code on an aspx page and <script src="UX/vendor/requirejs/require.min.js"> is commented out, you see the following.

This is an error when Require JS does not work with customer JS.


However, if the <script src="UX/vendor/requirejs/require.min.js"> is not commented out, because the code is defining a module, the following error is thrown:

Uncaught error: Mismatched anonymous define()


To fix the problem, you must update your JavaScript define methods within RequireJS, according to following documentation: https://requirejs.org/docs/api.html#define.

For more in-depth description of how to avoid this and other RequireJS errors, see  http://requirejs.org/docs/errors.html#mismatch .