AnsweredAssumed Answered

How exactly should third party libraries be included in WAB through the lib/main?

Question asked by PavelVeselsky on Apr 6, 2016
Latest reply on Apr 25, 2016 by FloCAD

The official documentation for using other libraries in Web AppBuilder points to libs/main for including AMD modules in multiple widgets. I want to use Proj4js in my widgets, so I deployed it in the d:\WAB\client\stmapp\libs directory and added the path ("./proj4js/dist/proj4") into the libs/main.js dependency array. The path to the proj4.js file is d:\WAB\client\stmapp\libs\Proj4js\dist\proj4.js, which should be where the setting is pointing to. This should be enough according to the documentation, but it doesn't work. http://myname/webappviewer/?config=sample-configs/config-demo.json reads code from the client, so the problem shouldn't be in reading wrong address, but to be sure I copied the code to all WAB apps where I have the widget as well (stem app + all my apps).


Someone had a similar problem and solved it, though he asked for a non-AMD module and proj4js seems to be AMD-compliant, so his solution is unlikely to work for me. I tried everything they suggested there. I added window.path + 'libs/proj4js/dist/proj4.js' into the resources array in the Init.js file - this is suggested for static sources, but probably helped that guy. In the same file, I created dojoConfig.aliases with reference for proj4js:


dojoConfig.aliases = [
  ['Proj4js', 'libs/proj4js/dist/proj4']


I defined the library by the alias, but the first use of Proj4js in the code throws a "not found error" - obviously the alias is not recognized. I didn't find any other address to define the library in my widget which wouldn't throw the same error. In the linked discussion they omitted the definition, but I don't think it's the solution in my case.


  //other libraries
function (
  //other libraries
) {
  //other code

  //Proj4js unknown error here if definition omitted
  Proj4js.defs["EPSG:102067"] = "S-JTSK Krovak Proj4js definition";

  //the rest of my code


I intend to use this for multiple (perhaps even tens in the future) widgets, so I want to learn the lib/main methods even though I managed to enable proj4js for a single module. I deployed proj4js in my widget and defined it by relative path in my code: "./proj4js-2.3.14/dist/Proj4".


This question is based on my older GIS.stackexchange question.