JavaScript Error "Uncaught Error: Can only have one anonymous define call per script file"
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."
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.
Solution:
To solve the issue, we suggest loading the dependencies of the Bold BI script before loader.js through a workaround.
By default, Bold BI dependencies were added dynamically while initializing BoldBI.create().
- Probably, have the loader.js referred to before creating Bold BI.
- Here, we suggest you refer to the Bold BI dependencies statically, then by loader.js, before initializing BoldBI.create().
- 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.