Unable to load external module in mendix widget or application

0
Hi mendix community, We are having a problem building a widget around a javascript module. However we try to load this module it always seems to give some errors with the mendix modules.  The module has been developed by an external party. It has been implemented in several (non-mendix) applications so I'm pretty sure the problem's gotta be on our side. When we load this module in a widget we get the following error: 'Error: factoryThrew' from somewhere within mxui.js.   Beside this way we have have attempted to load this module directly from a script tag in index.html (so loading it next to mendix itself). This still gives us two errors;  'Error: multipleDefine' and the same 'Error: factoryThrew' as before. Both from mxui.js.  Especially in the last case I'm really surprised we end up in mxui.js by calling a package that can only call functions available in a regular javascipt environment. Does mx redefine/overwrite some default functions?  Anyone has had this problem before? Anyone knows a solution? Thanks in advance folks
asked
1 answers
0

Is it written in Dojo (Custom widget) or React (Pluggable widget)?

I have encountered this error many times writing a Dojo widget. You have to be sure you are importing the library in the correct manner with AMD. Please verify if that is the case. 
 

Next to that Mendix bundles it’s widgets whilst deploying with webpack, clustering all widgets in one file. If your widget is referencing some global variable also defined in another widget you can encounter the multiDefine error. I have experienced this many times because multiple widgets were loading the jQuery library and defining the jQuery variable $ multiple times.

EDIT: Since you are using Dojo, I would suggest to try and solve your problem in the following manner

  1. First try to find a AMD supported resource of your library file and with ‘Bundle widgets when running locally’ setting try to get it to work
  2. If this fails, try the ‘Check widgets’ feature in Studio Pro.
    1. This should tell you there is a problem with your widget 
    2. If an error occurs, the error can be found in the log file, to be located at: \deployment\data\tmp\dojo\build-report.txt

 

Sadly the build-report is not optimal and finding an error can be quite cumbersome, let alone fix it. In my experience it is then best to check any other properly build widget using complex external libraries. Heaps of these can be found in the AppStore. See specifically the beginning part of the JavaScript library file.

 

Good luck!

answered