<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic map.remove throws type error after removing the layer in ArcGIS JS API 4.3 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-remove-throws-type-error-after-removing-the/m-p/677896#M63216</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;I am trying to remove a layer from the mapView.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;var&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;LayertoRemove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;findLayerById&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;layerID&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);
&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;remove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;LayertoRemove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;The layer is found and is actually removed, but after it's removed it continues to throw &lt;SPAN style="border: 0px;"&gt;&lt;EM&gt;TypeError: this.controller.destroy is not a function&lt;/EM&gt;&lt;/SPAN&gt;, and the rest of the script is not run. when I remove these two lines of code, the script works fine.&amp;nbsp;the full error log is:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Uncaught&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;TypeError&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;this&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;controller&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;destroy is not a &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;510
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Object&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;d&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;detach &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;510&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Object&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;update &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;25&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at k&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;_animationFrame &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;init&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;329&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;The error in the console is pointing to MapView.js and init.js of the API and not to any line in my script.&amp;nbsp;&lt;/P&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;/SPAN&gt; The FeatureLayers that I am trying to remove are not hosted layers, but generated from client-side geometries (graphics are created from two csv files taken from the client); I suspect that the error is happening because of the setting of one of the properties of the layer -- which I probably need to set when the layer is created. &amp;nbsp;map.remove() works fine when I tested it with with a hosted layer. The &lt;SPAN&gt;FeatureLayers &lt;/SPAN&gt;are generated as follows and are added to map without any issue:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; createLayer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;graphics&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;type&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lyr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;new&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;FeatureLayer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;source&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; graphics&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;objectIdField&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"ObjectID"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;spatialReference&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;wkid&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;4326&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;geometryType&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; type&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;id&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;add&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lyr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:34:38 GMT</pubDate>
    <dc:creator>REZAAmindarbari2</dc:creator>
    <dc:date>2021-12-12T04:34:38Z</dc:date>
    <item>
      <title>map.remove throws type error after removing the layer in ArcGIS JS API 4.3</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-remove-throws-type-error-after-removing-the/m-p/677896#M63216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;I am trying to remove a layer from the mapView.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;var&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;LayertoRemove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;findLayerById&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;layerID&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);
&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;remove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;LayertoRemove&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;The layer is found and is actually removed, but after it's removed it continues to throw &lt;SPAN style="border: 0px;"&gt;&lt;EM&gt;TypeError: this.controller.destroy is not a function&lt;/EM&gt;&lt;/SPAN&gt;, and the rest of the script is not run. when I remove these two lines of code, the script works fine.&amp;nbsp;the full error log is:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Uncaught&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;TypeError&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;this&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;controller&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;destroy is not a &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;510
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Object&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;d&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;detach &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;510&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;Object&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;update &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;25&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;at k&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;_animationFrame &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;init&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;js&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;329&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;The error in the console is pointing to MapView.js and init.js of the API and not to any line in my script.&amp;nbsp;&lt;/P&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;/SPAN&gt; The FeatureLayers that I am trying to remove are not hosted layers, but generated from client-side geometries (graphics are created from two csv files taken from the client); I suspect that the error is happening because of the setting of one of the properties of the layer -- which I probably need to set when the layer is created. &amp;nbsp;map.remove() works fine when I tested it with with a hosted layer. The &lt;SPAN&gt;FeatureLayers &lt;/SPAN&gt;are generated as follows and are added to map without any issue:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; createLayer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;graphics&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;type&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lyr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;new&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;FeatureLayer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;source&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; graphics&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;fields&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;objectIdField&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"ObjectID"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;renderer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;spatialReference&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;wkid&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;4326&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;geometryType&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; type&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;id&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;title
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;map&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;add&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lyr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;);&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:34:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-remove-throws-type-error-after-removing-the/m-p/677896#M63216</guid>
      <dc:creator>REZAAmindarbari2</dc:creator>
      <dc:date>2021-12-12T04:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: map.remove throws type error after removing the layer in ArcGIS JS API 4.3</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-remove-throws-type-error-after-removing-the/m-p/677897#M63217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see anything wrong with the code you posted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Removing a client-side feature layer seems to work fine in this sample:&amp;nbsp;&lt;A class="link-titled" href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=layers-featurelayer-collection" title="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=layers-featurelayer-collection"&gt;ArcGIS API for JavaScript Sandbox&lt;/A&gt;&amp;nbsp;(I just added some code to remove the layer on click, seems to work fine).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could&amp;nbsp;take a look at that sample closely and see if you're doing anything different.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 May 2017 14:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/map-remove-throws-type-error-after-removing-the/m-p/677897#M63217</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2017-05-08T14:16:30Z</dc:date>
    </item>
  </channel>
</rss>

