# TypeError: Cannot read property 'instancedArrays' of undefined

**URL:** <https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800>\
**Category:** Questions\
**Created:** [September 22, 2019, 8:23pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800 "2019-09-22T20:23:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyildiz](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@cyildiz](https://forum.babylonjs.com/u/cyildiz)\
**Post date:** [September 22, 2019, 8:23pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/1 "2019-09-22T20:23:23Z")

</div>

Hello guys when I try to create BABYLON.Mesh.CreateSphere got “Cannot read property ‘instancedArrays’ of undefined” Error

Actually my code was in a class and working and I just moved it to another class and I start getting this error

> Blockquote

import { Component } from ‘@angular/core’;  
import \* as BABYLON from ‘babylonjs’;

@Component({  
selector: ‘app-home’,  
templateUrl: ‘./home.component.html’,  
styleUrls: [‘./home.component.css’]  
})  
export class HomeComponent {

private \_canvas: HTMLCanvasElement;  
private \_engine: BABYLON.Engine;  
private \_scene: BABYLON.Scene;  
private \_camera: BABYLON.TargetCamera;  
private \_light: BABYLON.Light;  
constructor() {  
this.\_canvas = document.getElementById(‘renderCanvas’);  
this.\_engine = new BABYLON.Engine(this.\_canvas, true);

}

createScene(): void {

```
this._scene = new BABYLON.Scene(this._engine);
this._camera = new BABYLON.TargetCamera('camera1', new BABYLON.Vector3(0, 5, -10), this._scene);
this._camera.setTarget(BABYLON.Vector3.Zero());
this._camera.attachControl(this._canvas, false);
this._light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), this._scene);
const sphere = BABYLON.Mesh.CreateSphere('sphere1', 16, 2, this._scene); //<<<<<<<<<<===================
sphere.rotation.x = Math.PI / 2;
sphere.position.y = 1;
sphere.actionManager = new BABYLON.ActionManager(this._scene);
const hl1 = new BABYLON.HighlightLayer('hl1', this._scene);
const ground = BABYLON.MeshBuilder.CreateGround('ground1',
  { width: 6, height: 6, subdivisions: 2 }, this._scene);
const pointerDragBehavior = new BABYLON.PointerDragBehavior({ dragAxis: new BABYLON.Vector3(0, 0, 0) });
pointerDragBehavior.useObjectOrienationForDragging = false;
pointerDragBehavior.updateDragPlane = false;
pointerDragBehavior.onDragStartObservable.add((event) => {
  console.log('dragStart');
  console.log(event);
})
pointerDragBehavior.onDragObservable.add((event) => {
  console.log('drag');
  console.log(event);
  sphere.position.y = event.dragPlanePoint.y;
  sphere.position.x = event.dragPlanePoint.x;
})
pointerDragBehavior.onDragEndObservable.add((event) => {
  console.log('dragEnd');
  console.log(event);

})
sphere.addBehavior(pointerDragBehavior);
const h1 = new BABYLON.HighlightLayer('hl', this._scene);
let lastClickedMesh = null;
this._scene.onPointerObservable.add((evt) => {
  if (evt.pickInfo.hit && evt.pickInfo.pickedMesh !== undefined) {
    const mesh = evt.pickInfo.pickedMesh;
    if (mesh.name.startsWith('sphere')) {
      if (lastClickedMesh !== null) {
        console.log('unhighlighting', lastClickedMesh);
        h1.removeMesh(lastClickedMesh);
      }
      lastClickedMesh = mesh;
      h1.addMesh(lastClickedMesh, BABYLON.Color3.Green());
    }
  }
}, BABYLON.PointerEventTypes.POINTERDOWN);

```

}

animate(): void {  
// run the render loop  
this.\_engine.runRenderLoop(() =\> {  
this.\_scene.render();  
});

```
// the canvas/window resize event handler
window.addEventListener('resize', () => {
  this._engine.resize();
});

```

}  
public Render() {  
this.createScene();

```
this.animate();

```

}

}

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 23, 2019, 8:16am UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/2 "2019-09-23T08:16:17Z")

</div>

You should provide a playground example, it will be easier to look for the problem.

Each time I encountered this error, it was because the canvas was not existing / was not properly given to Babylon engine. Make sure you have a canvas into your page and that it is properly used by the engine.

---

<div class="post-metadata">

**Author:** ![cyildiz](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@cyildiz](https://forum.babylonjs.com/u/cyildiz)\
**Post date:** [September 23, 2019, 10:46am UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/3 "2019-09-23T10:46:42Z")

</div>

> [@Evgeni\_Popov](#):
>
> to Babylon engine. Make sure you ha

yea it was because of I create canvas in constructor. when I move canvas creation into createscene method, problem was solved

---

<div class="post-metadata">

**Author:** ![ninkinoarimasu](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ninkinoarimasu/32/8999_2.png) [@ninkinoarimasu](https://forum.babylonjs.com/u/ninkinoarimasu)\
**Post date:** [April 16, 2020, 9:33am UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/4 "2020-04-16T09:33:44Z")

</div>

Uncaught TypeError: Cannot read property ‘instancedArrays’ of undefined at GroundMesh.Mesh [as constructor]

Why this problem happened? Can any one help me?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 16, 2020, 1:50pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/5 "2020-04-16T13:50:56Z")

</div>

As @Evgeni_Popov said earlier:

_"You should provide a playground example, it will be easier to look for the problem._

_Each time I encountered this error, it was because the canvas was not existing / was not properly given to Babylon engine. Make sure you have a canvas into your page and that it is properly used by the engine."_

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [May 19, 2020, 8:29am UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/6 "2020-05-19T08:29:32Z")

</div>

Just ran into the same error:

```auto
babylon.js:16 Uncaught (in promise) TypeError: Cannot read property 'instancedArrays' of undefined

```

In my case, this occured when calling `document.getElementById('renderCanvas')` when `<canvas id="renderCanvas" />` did not exist in the HTML file.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 19, 2020, 2:18pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/7 "2020-05-19T14:18:45Z")

</div>

Repro in the Playground?

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [May 19, 2020, 6:58pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/8 "2020-05-19T18:58:04Z")

</div>

Done! [https://playground.babylonjs.com/#7F75W1#1](https://playground.babylonjs.com/#7F75W1#1) Please view the console log for the `TypeError`.

Thank you for already resolving the issue. Just reproduced the console error for your reference.

Added only these lines:

```auto
// intentional wrongly initialized canvas and engine
var canvas2 = document.getElementById('nonexistantCanvas') as HTMLCanvasElement;
var engine2 = new BABYLON.Engine(canvas2, true);

var scene = new BABYLON.Scene(engine2); // using wrongly initialized engine2

```

---

<div class="post-metadata">

**Author:** ![8Observer8](https://avatars.discourse-cdn.com/v4/letter/8/bbe5ce/32.png) [@8Observer8](https://forum.babylonjs.com/u/8Observer8)\
**Post date:** [December 9, 2020, 2:44pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/9 "2020-12-09T14:44:09Z")

</div>

@gbz, thanks! I did not have this error in TypeScript but now I need to program in JS. I spent some time to find the solution.

---

<div class="post-metadata">

**Author:** ![kmitov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kmitov/32/4969_2.png) [@kmitov](https://forum.babylonjs.com/u/kmitov)\
**Post date:** [February 14, 2023, 12:46pm UTC](https://forum.babylonjs.com/t/typeerror-cannot-read-property-instancedarrays-of-undefined/5800/10 "2023-02-14T12:46:25Z")

</div>

Got to it while migrating from 4.2.0 to 5.46.  
Couple of specs failed and it turned out that for 4.2.0 we could run the specs with null canvas in the specs, while later we could not.

Thanks for pointing this out
