Search code examples
javascriptrequirejsarcgisarcgis-js-api

Problem with multipe require functions (RequireJS and ArcGIS JS API)


I'm currently looking for a way to use the module loader RequireJS and the ArcGIS JS API in a project. According to the documentation, the modules of the ArcGIS JS API can be loaded as shown in the following code snippet:

require(["esri/config", "esri/Map", "esri/views/MapView"], function (
  esriConfig,
  Map,
  MapView
) {
  //...
});

The problem is that if I want to load the modules from the ArcGIS JS API, it actually calls the Require function of RequireJS:

enter image description here

But it should load the require function which is defined in the ArcGIS JS API:

enter image description here

RequireJS does not find the modules of the ArcGIS JS API and therefore throws errors in the console:

enter image description here

My project only supports ES5. For this reason I can't use node libraries like the esri-loader.


Solution

  • I found the solution. I had to add the following code:

    require.config({
        paths: {
          esri: "https://js.arcgis.com/4.18/esri",
          dojo: "https://js.arcgis.com/4.18/dojo",
          dojox: "https://js.arcgis.com/4.18/dojox",
          dijit: "https://js.arcgis.com/4.18/dijit",
          "@dojo": "https://js.arcgis.com/4.18/@dojo",
          cldrjs: "https://js.arcgis.com/4.18/cldrjs/dist/cldr",
          globalize:
            "https://js.arcgis.com/4.18/cldrjs/dist/globalize/dist/globalize",
          maquette: "https://js.arcgis.com/4.18/maquette/dist/maquette.umd",
          "maquette-css-transitions":
            "https://js.arcgis.com/4.18/maquette-css-transitions/dist/maquette-css-transitions.umd",
          "maquette-jsx":
            "https://js.arcgis.com/4.18/maquette-jsx/dist/maquette-jsx.umd",
          moment: "https://js.arcgis.com/4.18/moment",
          tslib: "https://js.arcgis.com/4.18/tslib/tslib",
        },
      });
    

    I found this solution in the following project: https://github.com/r-pankevicius/arcgis-js-api-with-requirejs/blob/master/4.13/scripts/main.js