cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

"has is not a function" when loading dojo 1.9.1 #237

Closed HendrikJan closed 10 years ago

HendrikJan commented 10 years ago

Hello,

Loading a Dojo application gives me an error. This error seems to pop up in about 50% of the times I load the application in Firefox, after clearing the cache.

To me the error seems to originate in curl but I might be mistaken...

The error states:

has is not a function            run.js (line 64)

@http://localhost/lib/dojo/request/default.js:6
core.executeDefFunc@http://localhost/lib/curl/src/curl.js:817
core.createResourceDef/execute<@http://localhost/lib/curl/src/curl.js:381
countdown/<@http://localhost/lib/curl/src/curl.js:239
core.createResourceDef/executeFactory/<@http://localhost/lib/curl/src/curl.js:403
CurlApi/then/<@http://localhost/lib/curl/src/curl.js:1218
Promise/promiseComplete/then<@http://localhost/lib/curl/src/curl.js:176
@http://localhost/lib/curl/src/curl.js:190
when@http://localhost/lib/curl/src/curl.js:215
CurlApi/then@http://localhost/lib/curl/src/curl.js:1221
when@http://localhost/lib/curl/src/curl.js:215
executeFactory@http://localhost/lib/curl/src/curl.js:398
allExportsReady@http://localhost/lib/curl/src/curl.js:937
countdown/<@http://localhost/lib/curl/src/curl.js:241
core.getDeps/getDep/exportOnce<@http://localhost/lib/curl/src/curl.js:898
countdown/<@http://localhost/lib/curl/src/curl.js:239
core.getDeps/getDep/resolveOnce<@http://localhost/lib/curl/src/curl.js:894
countdown/<@http://localhost/lib/curl/src/curl.js:239
core.getDeps/getDep/<@http://localhost/lib/curl/src/curl.js:925
notify@http://localhost/lib/curl/src/curl.js:169
@http://localhost/lib/curl/src/curl.js:202
core.createResourceDef/executeFactory/<@http://localhost/lib/curl/src/curl.js:404
CurlApi/then/<@http://localhost/lib/curl/src/curl.js:1218
Promise/promiseComplete/then<@http://localhost/lib/curl/src/curl.js:176
@http://localhost/lib/curl/src/curl.js:190
when@http://localhost/lib/curl/src/curl.js:215
CurlApi/then@http://localhost/lib/curl/src/curl.js:1221
when@http://localhost/lib/curl/src/curl.js:215
executeFactory@http://localhost/lib/curl/src/curl.js:398
allExportsReady@http://localhost/lib/curl/src/curl.js:937
countdown/<@http://localhost/lib/curl/src/curl.js:241
collect@http://localhost/lib/curl/src/curl.js:848
countdown/<@http://localhost/lib/curl/src/curl.js:239
core.getDeps@http://localhost/lib/curl/src/curl.js:865
core.defineResource@http://localhost/lib/curl/src/curl.js:831
core.fetchResDef/<@http://localhost/lib/curl/src/curl.js:962
process@http://localhost/lib/curl/src/curl.js:707

Lines 1 to 7 in /lib/dojo/request/default.js state (error seems to occur on line 6):

define([
    'exports',
    'require',
    '../has'
], function(exports, require, has){
    var defId = has('config-requestProvider'),
        platformId;

This looks to me like the callback function to define is called before '../has' is loaded. I'll try to dive a bit deeper into this issue this weekend, but am not sure I'll be able to understand a lot of the curl code.

Oh, to be complete; I load the code like this:

(function(curl) {

    var config = {
        baseUrl: '/',
        //paths: {
            // Configure paths here
        //},
        packages: [
            // Add third-party packages here
            { name: 'curl',  location: 'lib/curl/src/curl' },
            { name: 'wire',  location: 'lib/wire', main: 'wire' },
            { name: 'cola',  location: 'lib/cola', main: 'cola' },
            { name: 'rest',  location: 'lib/rest', main: 'rest' },
            { name: 'msgs',  location: 'lib/msgs', main: 'msgs' },
            { name: 'when',  location: 'lib/when', main: 'when' },
            { name: 'meld',  location: 'lib/meld', main: 'meld' },
            { name: 'poly',  location: 'lib/poly' },
            { name: 'dijit', location: 'lib/dijit' }, // dojo 1.9.1
            { name: 'dojo',  location: 'lib/dojo' }, // dojo 1.9.1
            { name: 'dojox', location: 'lib/dojox' }, // dojo 1.9.1
            { name: 'util',  location: 'lib/util' }, // dojo 1.9.1
            { name: 'dgrid', location: 'lib/dgrid' },
            { name: 'put-selector', location: 'lib/put-selector' },
            { name: 'xstyle', location: 'lib/xstyle' }
        ],
        // Turn off i18n locale sniffing. Change or remove this line if you want
        // to test specific locales or try automatic locale-sniffing.
        locale: false,
        // Polyfill everything ES5-ish
        preloads: [
            'poly/all', // Polyfill everything ES5-ish
            'curl/shim/dojo18' // shim for dojo 1.9.1
        ]
        // Or, select individual polyfills if you prefer
        //preloads: ['poly/array', 'poly/function', 'poly/json', 'poly/object', 'poly/string', 'poly/xhr']
    };

    curl(config, [
        'css!lib/dgrid/css/dgrid',
        'css!lib/dijit/themes/claro/claro',
        'css!theme/bones/admin',
        'wire!app/admin/main.spec'
    ]).then(success, fail);

    // Success! curl.js indicates that your app loaded successfully!
    function success () {
        /* some code */
    }

    // Oops. curl.js indicates that your app failed to load correctly.
    function fail (ex) {
        /* some code */
    }

})(curl);
unscriptable commented 10 years ago

Thanks for the detail, @HendrikJan!

Your config looks correct. The "50% of the times" sounds like a race condition, which is strange to me. The preloads option has been working for quite a while.

Can you try the dist version of curl: curl/dist/curl-for-dojo1.8/curl.js? This could eliminate the possibility that it's a race condition.

Hmmm.... wait. It's that the has module is missing, not the require.has. What could this be caused by?

Do you see any other errors in the console? Are there any 404s?

-- John

HendrikJan commented 10 years ago

Hi John,

The 50% was actually a bit exaggerated, now that I try to reproduce the error, it seems to be more like 5% or 10% of the times that I get the error.

Some more info:

The firebug output before and after the error are as follows: (the warning from has.js just before the error might be important)

ReferenceError: reference to undefined property plugin.facets
addPlugin(plugin.facets, this.facets, namespace);
registry.js (line 63)

TypeError: anonymous function does not always return a value
remove: function(id){
Memory.js (line 97)

SyntaxError: test for equality (==) mistyped as assignment (=)?
if(cmp = cellElement.widget){
editor.js (line 89, col 31)

SyntaxError: test for equality (==) mistyped as assignment (=)?
}else if(cmp = cellElement.input){
editor.js (line 96, col 36)

TypeError: anonymous function does not always return a value
} : function(object, value, cell, options){
editor.js (line 478)

TypeError: variable node redeclares argument
var node = registry.byNode(node);
Select.js (line 215, col 7)

SyntaxError: test for equality (==) mistyped as assignment (=)?
}while(base = bases[++pos]); // intentional assignment
declare.js (line 128, col 31)

SyntaxError: test for equality (==) mistyped as assignment (=)?
}while(base = bases[++pos]); // intentional assignment
declare.js (line 146, col 31)

SyntaxError: test for equality (==) mistyped as assignment (=)?
while(base = bases[++pos]){ // intentional assignment
declare.js (line 163, col 30)

SyntaxError: test for equality (==) mistyped as assignment (=)?
while(base = bases[++pos]){ // intentional assignment
declare.js (line 173, col 28)

TypeError: function inherited does not always return a value
function inherited(args, a, f){
declare.js (line 86)

TypeError: function inherited__debug does not always return a value
function inherited__debug(args, a1, a2){
declare.js (line 201)

TypeError: anonymous function does not always return a value
return function(){
declare.js (line 335)

TypeError: anonymous function does not always return a value
return function(){
declare.js (line 398)

TypeError: anonymous function does not always return a value
return function(){
declare.js (line 443)

TypeError: anonymous function does not always return a value
removeRow: function(rowElement){
Keyboard.js (line 154)

TypeError: anonymous function does not always return a value
masterName = "__" + dojo._scopeName + "ToDomId";
dom-construct.js (line 27)

TypeError: anonymous function does not always return a value
var keydownSignal = on(object, "keydown", function(evt){
connect.js (line 90)

ReferenceError: reference to undefined property window.navigator.msMaxTouchPoints
....add("touch", "ontouchstart" in document || window.navigator.msMaxTouchPoints > ...
has.js (line 101)

an error happened during loading :'(
run.js (line 63)
has is not a function
run.js (line 64)

@http://localhost/lib/dojo/request/default.js:6
k.R@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:15
k.C/f<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:9
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.C/c.H/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:9
B/a/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:6
A/e/a<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
u@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
B/a@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:6
u@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.C/c.H@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:9
k.r/t<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:16
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.r/d/e<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:15
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.r/d/d<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:15
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.r/d/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:16
b@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
k.C/c.H/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:9
B/a/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:6
A/e/a<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:4
u@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
B/a@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:6
u@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.C/c.H@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:9
k.r/t<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:16
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
b@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:15
x/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:5
k.r@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:16
k.D@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:15
k.V/<@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:16
k.ba/c.onreadystatechange@http://localhost/lib/curl/dist/curl-for-dojo1.8/curl.js:14

run.js (line 65)

ReferenceError: reference to undefined property tokens[+ (i)]
if(tokens[i++] == "?"){
has.js (line 136)

ReferenceError: reference to undefined property dua.split(...)[1]
has.add("msapp", parseFloat(dua.split("MSAppHost/")[1]) || undefined);
sniff.js (line 20)

TypeError: anonymous function does not always return a value
var signal = on(target, type, function(){
on.js (line 63)

SyntaxError: test for equality (==) mistyped as assignment (=)?
while(eventName = events[i++]){
on.js (line 102, col 32)

Regards, Hendrik Jan

HendrikJan commented 10 years ago

Hello John,

Thank you for your time and thinking.

The problem seems to be fixed. I changed some code seemingly unrelated to curl, related to lib/dgrid/Editor.

Unfortunately I don't have a good version control for my private projects. I'll try to reproduce what I did that fixed the problem but I'm not sure I can.

I think this issue is not caused by curl and can be closed.

Kind regards and thanks again, Hendrik Jan

HendrikJan commented 10 years ago

The problem seems fixes/not reproducible. Am I supposed to close the issue?????

unscriptable commented 10 years ago

Hey @HendrikJan,

This could be a circular dependency issue. The dojo guys seem to like circles. :) curl.js tries to handle them, but has some deep architectural issues that prevents it from fixing them 100%. The next major version of curl will handle cycles correctly all if the time.

If this happens again before curl 1.0, try using an artificial dependency to break the cycle. The one cycle I know in dojo concerns the dom*.js modules. If you require() one of those explicitly, it breaks the cycle.

I'll close this for now, but feel free to keep commenting if you see the issue again.

Regards,

-- John