[GIS] Error Multiple Define when loading base script

arcgis-javascript-apiarcgis-javascript-api-4javascript

I have an existing google maps-driven project that I'm trying to rebuild using Esri's JS API. Whenever I add the script tags <script src="https://js.arcgis.com/4.0"></script> to my page, I get Error: multipleDefine.

  • The dojo module listed changes sometimes on page load, but usually it's the localization modules. Sometimes it's an SVG module, IIRC.
  • This is a project I inherited from a vendor, so I'm still getting to know it, but as far as I can tell, there's no Esri or Dojo currently in the page.
  • The error occurs with both 3.16 and 4.0.
  • The issue does not occur in a test page with nothing but the map I want to show.

How can I debug this error?

Error text (3.16):

init.js:31 Error: multipleDefine(…)
init.js:31 src: dojoLoader
init.js:31 info: Object {pid: "esri", mid: "esri/nls/jsapi_en-us", pack: Object, url: "http://js.arcgis.com/3.16/esri/nls/jsapi_en-us.js", executed: 0…}

Error text (4.0):

init.js:24 Error: multipleDefine(…)
init.js:24 src: dojoLoader
init.js:24 info: Object {pid: "dojo", mid: "dojo/nls/dojo_en-us", pack: Object, url: "http://js.arcgis.com/4.0/dojo/nls/dojo_en-us.js", executed: 0…}

Best Answer

This error is caused by having jquery/jqueryUI loading at the same time from Esri's Dojo configuration and in our script. Per the thread here, putting the Esri script at the bottom of the page after jQuery was done loading removed the error and got everything working.

Future Me revisiting this question - it seems that anything that uses AMD/Require-style define conflicts with dojo's define as implemented in the Esri library. This is particularly notable in module-based libraries, and libraries designed to be used in node.js or the browser. Datatables is a good example, simply removing define from the initial environment/tech check solves the problem. Some libraries might need define renamed if they rely on it without a fallback.

Related Question