I am trying to update legacy map code to the latest ArcGIS version of 4.6 and noticed this warning in the console when querying a feature layer.

[esri.core.Promise] DEPRECATED: then() -- use .when(callback, errback) instead

So I tried to change then to when, but got when is not a function errors. I also tried running the sample code from the site and got the same errors.

view.whenLayerView(featureLayer).then(function(lyrView) {
          lyrView.watch("updating", function(val) {
            if (!val) { // wait for the layer view to finish updating

              // query all the features available for drawing.
              lyrView.queryFeatures().then(function(results) {

                graphics = results;

                var fragment = document.createDocumentFragment();

                results.forEach(function(result, index) {
                  var attributes = result.attributes;
                  var name = attributes.ZIP + " (" +
                    attributes.PO_NAME + ")"

                  // Create a list zip codes in NY
                  var li = document.createElement("li");
                  li.tabIndex = 0;
                  li.setAttribute("data-result-id", index);
                  li.textContent = name;

                // Empty the current list
                listNode.innerHTML = "";

I also tried setting the "esri-promise-compatibility" flag to 1 but that didn't help. Can't see anything in the docs or community forums about this. Anyone come across this before?

  • At which point of your code the error when is not a function throws?
    – Katah
    Mar 6, 2018 at 8:14
  • 1
    If I change view.whenLayerView(featureLayer).then( to view.whenLayerView(featureLayer).when(. From the docs it appears that LayerView supports when but it doesn't seem to work ref: developers.arcgis.com/javascript/latest/api-reference/… Mar 6, 2018 at 17:31

2 Answers 2


At the current Api the whenLayerView() is a promise but at the moment it doesn't support the when() funcion as you can see below the only supported are :


Also the warning shown in the console is due to this new version API () , May be it'll be removed or fixed in the newer versions ,

As you can see in this Fiddle Example (simple MapViewew without layers ), whether using promises or just create a simple map ,

the Warning still printed in console .

so using view.whenLayerView is not deprected . and the problem reside in the new version .


This can be very confusing. Not all then() should be replaced with when(), only then() which are implemented on classes, like WebMap, WebScene, MapView, SceneView, Basemap, Ground, Layers, and LayerViews.

The methods return ES6 compatible promises that implement the then() method. So in your example you don't need to do anything about the whenLayerView(layer) method, because that returns an ES6 compatible promise and that works with then.

You can read more about it in this blog post: https://www.esri.com/arcgis-blog/products/js-api-arcgis/mapping/making-better-promises/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.