Select to view content in your preferred language

Custom module not loading

3238
8
Jump to solution
08-09-2013 08:26 AM
PeteVitt
Frequent Contributor
Hi - I'm trying to use a custom module with the esri javascript library and an object expected error gets thrown on the require function:  It works just fine when I use "http://ajax.googleapis.com/ajax/libs/dojo/1.8.5/dojo/dojo.js" instead of js.arcgis.com/3.6/.  Any ideas what I'm doing wrong?

Thanks

<script
data-dojo-config="
        async: true,
       packages: [ {
            name: 'custom',
            location: location.pathname.replace(/\/[^/]+$/, '') + '/Scripts/custom'
        } ]"
        src="js.arcgis.com/3.6/">
</script>
</head>
<body class="claro">
    <div id="grid"></div>
    <script>

        require(["custom/ModTest"], function (ModTest) {
            ModTest.increment();
            var test = ModTest.getValue();
        });
       
    </script>
</body>
0 Kudos
1 Solution

Accepted Solutions
PeteVitt
Frequent Contributor
I got it to work -- I followed the method in an esri sample for specifying the module:

<script>var dojoConfig = {
        parseOnLoad:true,
        packages: [{
          "name": "custom",
          "location": location.pathname.replace(/\/[^/]+$/, "") + "/Scripts/custom"
        }]
      };
    </script>
    <script src="http://js.arcgis.com/3.6/"></script>


vs what I had before

<script
data-dojo-config="
        async: true,
       packages: [ {
            name: 'custom',
            location: location.pathname.replace(/\/[^/]+$/, '') + '/Scripts/custom'
        } ]"
        src="http://js.arcgis.com/3.6/>
</script>

View solution in original post

0 Kudos
8 Replies
JeffJacobson
Frequent Contributor
One problem I see is that you're missing the protocol before "js.arcgis.com/3.6/". You should use "//js.arcgis.com/3.6/" (You do not need to include http: or https: before the //, though.)

Here's some code I used recently which specifies a path in the dojoConfig variable instead of packages.

[HTML]<script>
    (function () {
        "use strict";
        var url, re = /\/[^\/]+$/;


        // Get the URL of this page without the query string.
        url = location.href.match(/^[^?]+/)[0];

        // Remove the document filename if present.
        if (re.test(url)) {
            url = url.replace(re, "/");
        }

        var dojoConfig = {
            async: true,
            paths: {
                "mymodules": url + "Scripts/mymodules"
            }
        };

        window.dojoConfig = dojoConfig;
    }());
</script>
<script src="//js.arcgis.com/3.6compact/"></script>[/HTML]
0 Kudos
derekswingley1
Deactivated User
Using paths or packages is work-able. Do you see a request being made to Scripts/custom/ModTest.js?
0 Kudos
PeteVitt
Frequent Contributor
Using paths or packages is work-able. Do you see a request being made to Scripts/custom/ModTest.js?


No, its throwing the error in //js.arcgis.com/3.6/ -- 'Object doesnt support this property or method' -- not making it to the custom module.

Thanks

Pete
0 Kudos
JasonZou
Frequent Contributor
Use Chrome to load your page, and open Developer Tools (Ctrl-SHIFT-i), in which click Network. Then refresh your page and check the url of the request to your custom module. More than likely, the url is incorrect. Correct it if possible.
0 Kudos
PeteVitt
Frequent Contributor
Use Chrome to load your page, and open Developer Tools (Ctrl-SHIFT-i), in which click Network. Then refresh your page and check the url of the request to your custom module. More than likely, the url is incorrect. Correct it if possible.


the custom module fires when I swap out the dojo in the esri script: //js.arcgis.com/3.6/
with
dojo located at google:  http://ajax.googleapis.com/ajax/libs/dojo/1.8.5/dojo/dojo.js
0 Kudos
JasonZou
Frequent Contributor
I am trying to narrow down the issue whether your custom module can be located or something needs to be changed with your custom module due to the change of dojo source. JS API v3.6 is using dojo 1.8.3. Unless you have used some new dojo features that are available in dojo 1.8.5, but not 1.8.3, otherwise I would be surprised it is the code issue if works for dojo 1.8.5.

I would check the module url using Developer Tools making sure it is correct. If so, I would make some breakpoints inside the entry function of the module when it's loaded, and see which step fails.
0 Kudos
PeteVitt
Frequent Contributor
I am trying to narrow down the issue whether your custom module can be located or something needs to be changed with your custom module due to the change of dojo source. JS API v3.6 is using dojo 1.8.3. Unless you have used some new dojo features that are available in dojo 1.8.5, but not 1.8.3, otherwise I would be surprised it is the code issue if works for dojo 1.8.5.

I would check the module url using Developer Tools making sure it is correct. If so, I would make some breakpoints inside the entry function of the module when it's loaded, and see which step fails.


Thanks - I've tried:

switching to src="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"> --> still works

I've set a break point when the module function gets called  -- when the google api is used the module function gets called.  When the esri api is used the module function doesnt get called.  Somehow the way I'm specifying the custom module isnt working for the esri api.  The module is just a simple test function that returns a number.  I'll keep searching for other examples.





Thanks for your help

Pete
0 Kudos
PeteVitt
Frequent Contributor
I got it to work -- I followed the method in an esri sample for specifying the module:

<script>var dojoConfig = {
        parseOnLoad:true,
        packages: [{
          "name": "custom",
          "location": location.pathname.replace(/\/[^/]+$/, "") + "/Scripts/custom"
        }]
      };
    </script>
    <script src="http://js.arcgis.com/3.6/"></script>


vs what I had before

<script
data-dojo-config="
        async: true,
       packages: [ {
            name: 'custom',
            location: location.pathname.replace(/\/[^/]+$/, '') + '/Scripts/custom'
        } ]"
        src="http://js.arcgis.com/3.6/>
</script>
0 Kudos