最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: defineAlreadyDefined - Stack Overflow

programmeradmin2浏览0评论

I get this error: Error: defineAlreadyDefined, that only occurs with dojo.

index.php

<script data-main="app" src="require.js"></script>

app.js

require({
    paths : {
        dojo : '.7.1/dojo/dojo'
    }
});

require([ 'dojo' ], function() {
   //something
});

I found a similar question, but didn't help me:

When dojo.js loaded via ajax multiple times get Error: defineAlreadyDefined

EDIT: I searched and I think the way that i am trying to use requiJS and Dojo is wrong. .6/async-modules

Any idea? thanks

I get this error: Error: defineAlreadyDefined, that only occurs with dojo.

index.php

<script data-main="app" src="require.js"></script>

app.js

require({
    paths : {
        dojo : 'http://ajax.googleapis./ajax/libs/dojo/1.7.1/dojo/dojo'
    }
});

require([ 'dojo' ], function() {
   //something
});

I found a similar question, but didn't help me:

When dojo.js loaded via ajax multiple times get Error: defineAlreadyDefined

EDIT: I searched and I think the way that i am trying to use requiJS and Dojo is wrong. http://dojotoolkit/features/1.6/async-modules

Any idea? thanks

Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked Apr 18, 2012 at 17:12 user947462user947462 9496 gold badges18 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

In order to use a foreign loader w/ dojo you need to skip the dojo/dojo.js file, which defines the AMD loader. Your require config should have something like:

require({
    packages: [
        {
            name: 'dojo',
            location: 'dojo',
            main:'dojo/main' 
        }
    ]
});

However, the dojo loader is just as good at loading jQuery plugins as requireJS and it es with a few additional plugins, like dojo/has. I'd give serious thought to just using it's loader.

Im not sure of what you want to acplish here, but Dojo implements requireJS. Therefore you don't need requireJS.

What you would do, for the normal use of Dojo library, is:

//call dojo script
<script src="http://ajax.googleapis./ajax/libs/dojo/1.7.2/dojo/dojo.js"></script>
<script>
    var dojoConfig = (function(){
        return {
            async: true,
            //in case you wanted to use your own library
            paths: [{
                name: "location/library"//your library path
            }]
        };
    })();       

    require([
        "dojo/parser",
        "name/something",//calling 'somethong' from library
        "dojo/domReady!"
    ], function(parser, something /*your library obj*/){
        //your logic
        parser.parse();
        something.do();
    });
});
</script>
发布评论

评论列表(0)

  1. 暂无评论