ArcGIS Experience Builder Widget: WebMap add() fails with "item is not a layer" due to a race condition.

189
2
08-08-2025 07:19 AM
Labels (2)
AbiDhakal
Frequent Contributor

Hello GIS friends,

I'm encountering a persistent race condition in my ArcGIS Experience Builder widget, developed using developer edition 1.17 for ArcGIS Enterprise 11.5. The console shows [esri.WebMap] #add() The item being added is not a layer or a promise that resolves to a layer. While also displaying my custom success log, "GraphicLayer added to map." This indicatges that the add() call fails asynchronously while the code proceeds, leading to a subsequent Uncaught TypeError when the Sketch widget attempts to use the failed layer. Despite having implemented wait on both graphicLayer.load() and jimuMapView.view.map.add(graphicLayer) to fix the timing, the error persists. I'm looking for a solution or a robust workaround to resolve this race condition and successfully add a GraphicLayer for my Sketch widget.

Thank you for your help and time.
Abi 

0 Kudos
2 Replies
JeffreyThompson2
MVP Frequent Contributor

https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout

I use setTimeout a lot. Sometimes there is just no practical solution, but adding a 50-500 millisecond delay using setTimeout. Often using more elegant methods like reactiveUtils or the layers ready property fail because the object must be written to memory before they will work and by the time they are they are in the ready state. 

GIS Developer
City of Arlington, Texas
0 Kudos
AbiDhakal
Frequent Contributor

Thank you @JeffreyThompson2. I appreciate your response and idea. I will have to give that a shot when I'm working on another widget, and the issue arises again.

0 Kudos