# Uncaught TypeError: Cannot read properties of null (reading 'width') at new WebGLRenderer

**URL:** <https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082>\
**Category:** Questions\
**Created:** [June 16, 2025, 11:03am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082 "2025-06-16T11:03:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:03am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/1 "2025-06-16T11:03:10Z")

</div>

Hi everyone

This is my code

````js
const sizes={
    width:800,
    height:600
}
const renderer=new THREE.WebGLRenderer({
    canvas
})

renderer.SetSize(sizes.width, sizes.height)

renderer.render(scene, camera)```
````

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:03am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/2 "2025-06-16T11:03:36Z")

</div>

I don’t understand what is going wrong in this code

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [June 16, 2025, 11:05am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/3 "2025-06-16T11:05:26Z")

</div>

1. What is `canvas` and how / where is it defined?
2. `renderer.SetSize` → `renderer.setSize`

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:19am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/4 "2025-06-16T11:19:16Z")

</div>

Hi thanks for your message

about canvas

 ![canvas](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/8/c/8cf3d1cfe333633372f753d338c700fadcbc590e.jpeg)

in mainjs I define it on top

````js
renderer.setSize(sizes.width, sizes.height)```
````

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:20am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/5 "2025-06-16T11:20:25Z")

</div>

still have the same error

 ![sill](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/6/c/6cf95d283f1de8dbe484e2b8f604c4eacdaf98af.jpeg)

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [June 16, 2025, 11:30am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/6 "2025-06-16T11:30:04Z")

</div>

```javascript
const renderer=new THREE.WebGLRenderer({
    canvas
})

```

to

```javascript
const renderer=new THREE.WebGLRenderer({
    canvas:document.getElementsByClassName("webgl")
})

```

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [June 16, 2025, 11:33am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/7 "2025-06-16T11:33:22Z")

</div>

☝ `webl`, there’s a typo in the class name 😭

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:33am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/8 "2025-06-16T11:33:38Z")

</div>

````js
import * as THREE from "three"

console.log(THREE)

const canvas=document.querySelector('.webgl')

const scene=new THREE.Scene()

const geometry=new THREE.BoxGeometry(1,1,1)
const material=new THREE.MeshBasicMaterial({color:'dodgerblue'})

const mesh=new THREE.Mesh(geometry, material)
scene.add(mesh)

const sizes={
    width:800,
    height:600
}

const camera=new THREE.PerspectiveCamera(75,sizes.width / sizes.height)
scene.add(camera)

const renderer=new THREE.WebGLRenderer({
    canvas
})

renderer.setSize(sizes.width, sizes.height)

renderer.render(scene, camera)```
````

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:34am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/9 "2025-06-16T11:34:57Z")

</div>

thanks guy

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 11:37am UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/10 "2025-06-16T11:37:23Z")

</div>

Thanks guy for your message I found the problem in the html I wrote webl ==\>webgl

---

<div class="post-metadata">

**Author:** ![pat66](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pat66](https://discourse.threejs.org/u/pat66)\
**Post date:** [June 16, 2025, 1:56pm UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/11 "2025-06-16T13:56:36Z")

</div>

guy I have a question about what is written inside renderer  
in my case I have a canvas in my html and the name of my canvas variable is canvas also.

in the case I call my canvas variable icecream

I should writte this

canvas: icecream

the first canvas is the html element and the second one is the name of variable ?

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [June 16, 2025, 2:14pm UTC](https://discourse.threejs.org/t/uncaught-typeerror-cannot-read-properties-of-null-reading-width-at-new-webglrenderer/84082/12 "2025-06-16T14:14:09Z")

</div>

```javascript
const canvas=document.querySelector('.webgl');
const renderer=new THREE.WebGLRenderer({canvas:canvas});

```

First canvas is property of renderer, and second canvas is value.  
Like `renderer.canvas=canvas;`
