How can I fix this AMD path conflict?

眉间皱痕 提交于 2019-12-01 11:25:37

I work with Esri's ArcGIS API so I've run into this exact problem. This blog post from dojo helped me out some.

The first issue is that dojo isn't configured the same way requirejs is. It looks for a previously defined dojoConfig to set things up. The second is that Esri's module loading is all set up assuming one basepath, and your code is going to want another. You're going to need a dojo config that looks something like this:

dojoConfig = {
    baseUrl: location.pathname.replace(/\/[^/]+$/, '') + '/Content/client/hop/',  // magic!
    packages: [
        {
            name: 'dojo',
            location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/dojo/dojo/"
        },
        {
            name: 'dojox',
            location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/dojo/dojox"
        },
        {
            name: 'esri',
            location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact/js/esri"
        }
    ]
};

What this is doing is setting the basepath back to the current url plus your extra stuff, and then telling dojo where esri's stuff is. Those are all the packages that I've run into but if there's a dependency I missed because it just never loaded for me, it will need a similar entry.

Another problem you might run into is that if you're used to loading your script locally as file:// now dojo from another domain is going to try to access file:// and the browser is going to shut that right down. You'll need to test on a local http server from now on. On Windows I prefer HFS and on Linux python makes it easy.

I hope this helps.

I've had several problems using dojo together with requirejs because of the require() conflicts between the two. You should take a look at dojo bug 15616. You might want to look at this thread from google groups in which James suggest all dojo or all requirejs.

I'm not sure what version of dojo you're using but checking out from source is advised as there are changes related to requirejs/dojo that are not in the published 1.8.

If your only problem is 404 errors caused by the baseUrl conflict a workaround would be creating a .d.ts file that aliases a path like ../classes/trace and replaces it with a path that works (absolute or otherwise).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!