Articles in this section
Category / Section

JavaScript Error "Uncaught Error: Can only have one anonymous define call per script file"

Published:

Issue:

While using the Microsoft loader.js as part of a component in the embedding application, it does not allow loading the Bold BI embedded libraries. In this case, the console error will be logged as "Can only have one anonymous define call per script file."

Uncaught Error: Can only have one anonymous define call per script fileUncaught Error: Can only have one anonymous define call per script file 

Reason:

Asynchronous module definition (AMD) is a specification for the programming language JavaScript. It defines an application programming interface that defines code modules and their dependencies and loads them asynchronously if desired.

The Microsoft Asynchronous module definition (AMD) loader "loader.js" is programmed to load AMD definitions by default. However, this only permits a single defined call per script file. If multiple definitions are required in the same file, an exception will be displayed as "Not more than one anonymous define call." Bold BI and its script dependencies have multiple anonymous AMD definitions, which causes the exception to be thrown when attempting to load anonymously.

Solution:

To solve the issue, we suggest loading the dependencies of the Bold BI script before loader.js through a workaround.

  1. By default, Bold BI dependencies were added dynamically while initializing BoldBI.create().

  2. Probably, have the loader.js referred to before creating Bold BI.
  3. Here, we suggest you refer to the Bold BI dependencies statically, then by loader.js, before initializing BoldBI.create().
  4. BoldBI.create() doesn’t allow the dependencies to add duplicates.

By default,

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsrender/1.0.0-beta/jsrender.min.js"></script>


<script type="text/javascript" src="/js/Embed/EmbedBIWrapper.js"></script>


<script type="text/javascript" src="/js/Embed/Index.js"></script>


<!-- AMD loader file -->


<script type="text/javascript" src="/js/loader.js"></script> // Here the loader file referred before initializing BoldBI.create()


<!-- Bold BI script files -->


<script src="http://localhost:56942/bi/cdn/scripts/jquery-ui.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ejl.web.all.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ej2.web.all.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/designer/localization/designerlocalization.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ej.dashboarddesigner.min.js"></script>

After the changes,

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsrender/1.0.0-beta/jsrender.min.js"></script>


<script type="text/javascript" src="~/js/Embed/EmbedBIWrapper.js"></script>


<script type="text/javascript" src="~/js/Embed/Index.js"></script>


<!-- Bold BI script files -->


<script src="http://localhost:56942/bi/cdn/scripts/jquery-ui.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ej1.web.all.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ej2.web.all.min.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/designer/localization/designerlocalization.js"></script>


<script type="text/javascript" src="http://localhost:56942/bi/cdn/scripts/designer/ej.dashboarddesigner.min.js"></script>


<!-- AMD loader file -->


<script type="text/javascript" src="~/js/loader.js"></script>

// The loader.js file should refer after the Bold BI script files referred. Say after the BoldBI.create() Initialization.


Note: Here, http://localhost:56942 can be replaced with your Bold BI root URL.



Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SG
Written by Sivabalan Ganesan
Updated
Comments (0)
Please  to leave a comment
Access denied
Access denied