SystemJs – curModule.indexOf is undefined issue

Issue when using SystemJs

Recently we have migrated an AngularJs project in plain JS to ES6 with SystemJs and JSPM. When doing, we have faced an issue with SystemJs, it throws error ‘curModule.indexOf is undefined’ – and we were not able to continue.

Custom method in Array

After some days of analysis, we have found out, the problem is within our application. There are some methods added with Array object, which causes problem. It was added using,

Array.prototype.methodName = function() {

which is very bad, when it comes to for-in loop. With for-in loop, not only the items in array are iterated, but these methods too, with all the arrays. But, we will get the expected length.
To avoid this in out application, we could use a check hasOwnProperty, but what about the dependent libraries like SystemJs?

Use Array.defineProperty

Instead of using Array.prototype.someMethod = , we should use

Array.defineProperty(Array.prototype, "someMethod", {

By this way, we can avoid the issues with for-in loop within the application and with . After this change, curModule.indexOf issue was not faced.
Here is a code, to check how it affects the Array
We can find some more details here.