# TypeError: Cannot read properties of null (reading 'width')

**URL:** <https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [January 3, 2022, 2:48pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655 "2022-01-03T14:48:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 3, 2022, 2:48pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/1 "2022-01-03T14:48:27Z")

</div>

Hello!

I am trying to get an experiment online, but continue to get the following error:

TypeError: Cannot read properties of null (reading ‘width’)

which for a split second reads

TypeError: Cannot read properties of null (reading ‘uvsfloat32’)

before going back to ‘width’.

This happens after I change from the .append function in python to .push in JS. When opening the console through my browser, it reads the following:

FATAL 14:41:08.384 GUI.dialog psychojs-2021.2.3.js:1257 | {}  
BrowserConsoleAppender.append @ log4javascript.js:148

Because of this, I tried removing all python code whereby append was mentioned and including the code ‘Array.prototype.append = .push’ in the begin experiment tab but the problem persists…

Is anyone able to help with getting this to run? 🙂

Here is a link to the gitlab:

> **[Sarah Rutherford / Object Foraging](https://gitlab.pavlovia.org/SER/object-foraging/)**
>
> Sign In/Register

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 3, 2022, 2:52pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/2 "2022-01-03T14:52:39Z")

</div>

What version of PsychoPy are you using? The latest versions automatically translate append to push and will crash if you add `Array.prototype.append = .push` in Begin Experiment.

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 3, 2022, 3:25pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/3 "2022-01-03T15:25:42Z")

</div>

2021.2.3

Yes, the experiment failed to initalise with the array.prototype.append = .push. included…

However, without editing anything of the JS and keeping the auto translation from python (and thus it reads .append on both sides), it reads \* **TypeError: instr\_Clicked.append is not a function**.

When changing manually the .append to .push on the JS side, it gives the \* **TypeError: Cannot read properties of null (reading ‘width’)**

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 3, 2022, 3:34pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/4 "2022-01-03T15:34:49Z")

</div>

If you are using 2021.2.3 then you should be able to make any edit on the Python side (e.g. insert and then delete a character) in the Auto translate code component to get the 2021.2 translator to spot .append and replace it with .push on the JS side.

Here’s a possible solution to your main issue.

> [@Debuging "Cannot read properties of null (reading 'width')" REALLY NEEDS HELP](https://discourse.psychopy.org/t/debuging-cannot-read-properties-of-null-reading-width-really-needs-help/25217/11):
>
> Hi, After over 3000 runs of the experiment I think I have reached the source of the problem. Both stimuli (large circles with small dots) have a mask that hides their background, and of course is the same mask and the same file, when I remove from one of them the mask (which is not actually necessary for the experiment) has no crash. Maybe the source of the problem was the overlap between the masks? Maybe an overlap between two masks that are the same file? I do not know. But a sol…

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 3, 2022, 4:43pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/5 "2022-01-03T16:43:26Z")

</div>

I have replaced the .append with .push on the JS side, and it runs for one trial and then reads the error.

Checked out the linked solution and tried changing the mask files to separate ones (as not to use the same one but the masks are still necessary) and the error reads the same

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 3, 2022, 4:47pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/6 "2022-01-03T16:47:23Z")

</div>

Are you using Ctrl-Shift-R on an incognito tab in Chrome to ensure you run the latest code?

By “the error” I assume you mean the width error.

By replace .append with .push, do you mean that you got the Auto code component to change it automatically?

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 4, 2022, 11:28am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/7 "2022-01-04T11:28:10Z")

</div>

yes to the running the latest code, the error is indeed the width error, and the replacing of .append with .push is done manually

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 4, 2022, 12:01pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/8 "2022-01-04T12:01:35Z")

</div>

Look at your properties for instr\_target1

Your size is 0.09 set every repeat. Try [0.09,0.09] constant.

Why is instr\_setPos set to Both?

Why is if t \>= 1: continueRoutine = False in Begin Routine (it does nothing here because t = 0)

You have several psyexp files in the same folder. Pavlovia can only cope with one, so I hope you aren’t trying to use any of the older ones.

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 4, 2022, 4:05pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/9 "2022-01-04T16:05:01Z")

</div>

So, I changed the size to constant and 0.09, 0.09 (with and without square brackets), still the width error.

In absolute truth, I am not sure why instr\_setPos was on both… put it back to auto.

The t \>=1: continueRoutine = False has been moved to Each Frame. Nice spot thank you 🙂

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 4, 2022, 5:26pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/10 "2022-01-04T17:26:42Z")

</div>

If you’d like me to take another look, please could you save and sync your current psyexp file? The js files are currently from one hour ago but the psyexp file is from yesterday.

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 4, 2022, 6:20pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/11 "2022-01-04T18:20:50Z")

</div>

done!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 4, 2022, 9:02pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/12 "2022-01-04T21:02:36Z")

</div>

I have discovered that PsychoJS doesn’t like setting a mask if the image has zero opacity.

Here is a working version of your experiment using `instr_target1.setPos([2,2])` instead

[https://run.pavlovia.org/vespr/object-foraging](https://run.pavlovia.org/vespr/object-foraging)

---

<div class="post-metadata">

**Author:** ![ser](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ser/32/32047_2.png) [@ser](https://discourse.psychopy.org/u/ser)\
**Post date:** [January 5, 2022, 12:35pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-properties-of-null-reading-width/26655/13 "2022-01-05T12:35:32Z")

</div>

!! Very nicely found, clever solution also 🙂 Thank you!
