2

In my dojo app i am trying to dynamically load module which works fine until i build my code. Once code is build using dojo build system somehow the same module loads as an interger (specifically 3) rather than the module itself.

Below is the code that is working i.e. before building an app

var loadModule = "MyModule.js";
var path = "./js/path/to/MyModule/";
require([path+loadModule], lang.hitch(this,function (myModule) {
    //do something with myModule
   //this works without any problem
}))

Now the same piece of code when came through the dojo build system becomes something like below and doesn't work

var _23 = "MyModule.js";
var _24 = "./js/path/to/MyModule/";
require([_24 + _23], _2.hitch(this, function(_25) {
    //here this '_25' is number 3 instead of myModule. which i wonder why!
}))

For the dojo build system i am using following configurations

layerOptimize: "shrinksafe",
optimize: "shrinksafe",
cssOptimize: "comments",
mini: true,
stripConsole: "warn",
selectorEngine: "lite",

Edit: Here in my application the module i am trying to load dynamically is responsible for dealing with openlayers map. The basic code for this module goes like below

define(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/window", "dojo/dom", "dojo/dom-construct", "dojo/topic","dojo/dom-style","dojo/on",
        "dijit/registry","dijit/Tooltip","dijit/TooltipDialog","dijit/popup","dijit/ConfirmDialog",
        "dojox/collections/Dictionary"
        ],
        function(declare, lang, baseWindow, dom, domConstruct, topic, domStyle, on,
                registry,Tooltip,TooltipDialog,dijitPopup,ConfirmDialog,
                Dictionary){

    var olMapModule = {};

    olMapModule.initMap = function(){
        //Code for openlayer go here    
    };


    olMapModule.initMapInteractions = function(){
        //code for initiating the map interactions go here
    };
    return olMapModule;
});

Edit2: The comma was placed by mistake. Also the thing is, this piece of code does works perfect before going through the dojo build.

Suraj
  • 451
  • 1
  • 9
  • 17
  • Do you run the built code on the same machine ? I had that when using Windows for dev and Linux for built... There was a mistake in the case... A lower case instead of an upper one – ben Aug 25 '16 at 12:09
  • Not on the same machine, though on same os i.e. I use the ubuntu for dev as well as on build machine. Also the build process is automated using the maven plugin which wraps the dojo build in it to produce the production war. – Suraj Aug 25 '16 at 12:14
  • 1
    the extra comma after `"dojox/collections/Dictionary",` can be the cause (on IE) but more generally the "3" has few reasons: a 404 when requesting the module or a JS error when evaluating the module – ben Aug 25 '16 at 13:01

1 Answers1

0

Try to avoid string concatenation when using `require``instead specifiy in one string the path to your modeul. This should solve your issue:

require(["./js/path/to/MyModule/MyModule.js"], lang.hitch(this,function (myModule{}));
GibboK
  • 71,848
  • 143
  • 435
  • 658