Ios 10.3 Error: Uncaught (in promise): TypeError: Attempted to assign to readonly property

Hi all ! Could anyone suggest please … how to fix such error ?

Error: Uncaught (in promise): TypeError: Attempted to assign to readonly property.
file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/main.js:24174:42
onInvoke@file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/main.js:4427:43
run@file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/polyfills.js:3:4458
file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/polyfills.js:3:14079
onInvokeTask@file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/main.js:4418:47
runTask@file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/polyfills.js:3:5153
o@file:///Users/kirillgolovan/Library/Developer/CoreSimulator/Devices/F796DA57-3C13-4CEE-8C50-A93B70472A5F/data/Containers/Bundle/Application/F86CE30D-AA74-47B7-945A-C401B82E47AC/MyApp.app/www/build/polyfills.js:3:2210
promiseReactionJob@[native code] — polyfills.js:2

Post some context please.

ionic info output, what code you are running, when exactly you get this error.

Ionic info !

global packages:

@ionic/cli-utils : 1.4.0
Cordova CLI      : 7.0.1 
Ionic CLI        : 3.4.0

local packages:

@ionic/app-scripts              : 1.3.8
@ionic/cli-plugin-cordova       : 1.4.0
@ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms               : ios 4.4.0
Ionic Framework                 : ionic-angular 3.4.2

System:

Node       : v6.10.3
OS         : macOS Sierra
Xcode      : Xcode 8.3.3 Build version 8E3004b 
ios-deploy : not installed
ios-sim    : 6.0.0 
npm        : 3.10.10 

Sujan12, when I run this function, I see error …

Error: Uncaught (in promise): TypeError: Attempted to assign to readonly property.

  HotSpotClick(num,HotSpotPtrClick) {
    this.contentProvider.get_parts(this.contentItem.resourcePtr,this.model_id).then(data=> {

      console.log('HotSpotPtrClick',HotSpotPtrClick, "num ", num);
    
      let elem = document.getElementsByClassName("hotSpotDot");

      for(let i=0;i<elem.length;i++)
        elem[i].className =  elem[i].className.replace(/ active/g,"");

      this.navCtrl.push(PartsPage, {model_id: this.model_id, part_list:data,partNum:num,HotSpotPtrClick:HotSpotPtrClick,modelDesc:this.contentItem.resourceCaption});
    });
  }

How are you building/running your app?
Does this also happen on Android or ionic serve?
@ionic/app-scripts : 1.3.8 is old and can be upgraded to 1.3.12.

Sujan12, yes of course I am building/running my app on Android. On Android 4,5 I have the same error, but with
cordova-plugin-crosswalk-webview it working well ! Maybe issue is that once I enter the Promise I am in a different context; the “this” no longer points to the “this” ?

Not that clear when the title only includes “ios” and also the list of platforms doesn’t list “android”.[quote=“anton_klochko, post:5, topic:95853”]
On Android 4,5 I have the same error, but with
cordova-plugin-crosswalk-webview it working well !
[/quote]

Couly you expand on that? WHen does it work on Android, when doesn’t it?

Please answer that question. I want to know the command you execute on the CLI.[quote=“anton_klochko, post:5, topic:95853”]
Maybe issue is that once I enter the Promise I am in a different context; the “this” no longer points to the “this” ?
[/quote]

Possible. console.log can tell you.

Please answer that question. I want to know the command you execute on the CLI.

ionic build android --prod // for Android

ionic cordova run ios --livereload // for Ios

Couly you expand on that? WHen does it work on Android, when doesn't it?

On Android 4+,5+ I saw such error,but on Android 6+,7+ all working well without error !

Missing something for the Android command? cordova should be in there.

So it doesn’t work on iOS at all, on Android only for 6+7, not for 4+5. Correct?

Use identical commands to run/build - choose if you want to use --prod right now or not. Same for --livereload (I suggest to drop that). Then write again where it works and were it doesn’t.

So it doesn't work on iOS at all, on Android only for 6+7, not for 4+5. Correct?

Yes, on Android only for 6+7, not for 4+5+.

I am trying only iphone SE, I have problem to choose needable simulator.

Sujan12, this full error text,do not you know what this mean ?

Uncaught (in promise): TypeError: Cannot assign to read only property 'partDescription' of [object Object]↵TypeError: Cannot assign to read only property 'partDescription' of [object Object]↵

This is my function …

  public get_parts(resourcePtr, model_id):Promise<any> {
    return new Promise((resolve, reject)=> {
      let output = [];
      this.sql.query("SELECT * FROM model_" + model_id + "_boms as tb1  INNER JOIN model_" + model_id + "_parts as tb2 ON tb1.bomPartPtr =tb2.PartPtr WHERE tb1.resourcePtr=?  ORDER BY tb1.bomReference", [resourcePtr]).then(data=> {
        let localdesc = '';
        for (let i = 0; i < data.res.rows.length; i++) {
          if (data.res.rows.item(i).bomLocalDesc != null)
            localdesc = data.res.rows.item(i).bomLocalDesc.replace(/\{ItemObject\.Description}/g, " ");
          data.res.rows.item(i).partDescription = data.res.rows.item(i).partDescription + localdesc;
          output.push(data.res.rows.item(i));
        }
        this.sql.query("SELECT * FROM model_" + model_id + "_boms as tb1   WHERE (tb1.resourcePtr=?) AND (tb1.bomPartPtr IS NULL) ORDER BY tb1.bomReference", [resourcePtr]).then(data_new=> {
          for (let i = 0; i < data_new.res.rows.length; i++) {
            if (data_new.res.rows.item(i).bomLocalDesc != null)
              data_new.res.rows.item(i).partDescription = data_new.res.rows.item(i).bomLocalDesc.replace(/\{ItemObject\.Description}/g, " ");
            else
              data_new.res.rows.item(i).partDescription = '';
            let obj = Object.assign({PartPtr: '', id: '', notes: '', partCode: ''}, data_new.res.rows.item(i));
            output.push(obj);
          }
          Array.prototype.sort.call(output, function (a, b) {
            a = parseInt(a['bomReference']);
            b = parseInt(b['bomReference']);
            if (isNaN(a) && !isNaN(b))
              return 1;
            else if (!isNaN(a) && isNaN(b))
              return -1;
            else if (!isNaN(a) && !isNaN(b))
              return (a > b) ? 1 : (a < b) ? -1 : 0;
            else
              return -1;
          });
          resolve(output);
        });
      }).catch(err=> {
        reject(err)
      })
    });
  }

Sorry, no idea.
Does it work if your uncomment all the lines where partDescription is manipulated (... partDescription = ...)?

Sujan12, thanks a lot, I will try something. p.s Could you suggest please how to build for real device ? How to run app on real device ? I would like to test on real device to understand how it is work …

These are the correct commands for that - you “just” have to find out what is wrong with your code and fix it.

I would eliminate all direct DOM manipulation and replace it with Angular attribute bindings.

rapropos,good day ! Could you show some example please? I can’t find any idea several days…

I have similar issue with VirtualScroll. Strange thing that VirtualScroll is not generating this error on other (modal) page. Problem not relative to iOS 10.3! Just VirtualScroll!

Code of page with error:

this.items = [];
this.fullItems = [];
if (res.items) { // typically array
	let n: number = 0;
	this.fullItems[n] = [];
	this.fullItems[n]['items'] = [];
	this.fullItems[n]['date'] = res.items[0]['date'];
	this.fullItems[n]['items'].push(res.items[0]);
	for (let i = 1; i < res.items.length; ++i) {
	  if (this.fullItems[n]['date'] != res.items[i]['date']) {
	    this.fullItems[++n] = [];
	    this.fullItems[n]['items'] = [];
	  }
	  this.fullItems[n]['date'] = res.items[i]['date'];
	  this.fullItems[n]['items'].push(res.items[i]);
	}
	this.items = this.fullItems.slice(); // tried after error with this.items = this.fullItems;
} else {
	this.items = [];
}

template:

<ion-list [virtualScroll]="items" approxItemHeight="438px">
	<ion-item-group *virtualItem="let day">
		<ion-item-divider>{{ day.date | amDateFormat: 'DD.MM.YYYY (dddd)' }}</ion-item-divider> 
		<ion-item *ngFor="let i of day.items" (click)="showDetails(i)">
			<div float-right *ngIf="i.marks"><span *ngFor="let m of i.marks" class="d-mark d-mark{{mark.mark}}">{{ mark.mark_s }}</span></div>
			<h3><strong>{{ i.subject.name }}</strong></h3>
			<p>{{ i.theme }}</p>
			<p>{{ i.hw.desc }}</p>
		</ion-item>
	</ion-item-group>
</ion-list>

Code of modal page without error:

    this.fullItems = this.navParams.get('items'); // typically array
    this.items = this.fullItems;

template:

<ion-list [virtualScroll]="items" approxItemHeight="45px">
		<ion-item *virtualItem="let i" (click)="selectItem(i.base_code, i.name + ' ' + i.socr)">{{ i.name }} {{ i.socr }}</ion-item>
	</ion-list> 

Are you sure you want [] and not {} there?

change to {} not resolve issue. And I don’t get this error without VirtualScroll.

What issue? If your error is not identical, it doesn’t make sense to hijack an old thread…

Not so old. Last replay was only one moth ago. If needed I can create new topic for my problem.