| Reference | Downloads | Github

Problem running experiment on Pavlovia: TypeError: Cannot read property '_psychoJS' of undefined

URL of experiment: Sign in · GitLab

Description of the problem:
Hi, while building my very first psychopy experiment, I encountered a few problems. As I’m uploading my study to Pavlovia, I received this error message “TypeError: Cannot read property ‘_psychoJS’ of undefined”. I tried to change my code according to the Python to JS crib sheet, but this error message persisted. I’m wondering what could be some plausible cause to this? And how can I fix this problem?

Here’s a screenshot of the console log

Hey! Sorry for the slow reply. Does this error immediately after your experiment loaded?

Hi everyone! I’m a new user, am trying to upload an experiment to Pavlovia and am seeing the same error as reported above. I am going to document this to the best of my ability below, so this will be quite a long and verbose error report. But am desperate for help so would LOVE anybody’s insight into this.

Ok. Running PsychoPy v2021.2.3 locally on a Mac (OsX Sierra, 10.12.6). I have built my experiment using builder and then dropped a little bit of custom code in two routines with the Auto->JS set.

The code itself (very similar code in two different routines - for validating input before making the ‘continue’ button visible and changing the colour of polygons on mouse clicks) is making the experiment fall over. I have tried removing the code and re-uploading - and the experiment runs. BUT… all the procedures I have learnt in my recent 3 day workshop and following all the documentation I can find - has not helped me isolate the error. In fact to me it looks like some wierd very low level general kind of thing with constructors of generic objects or something. Hmmm…

Ok. Here are the deets.

Url: DPCLnPhishingVal 01 [PsychoPy]

Error message:

ScreenCap-Error Message

Using inspect, I see the console details the following errors:

The sources tab then reveals the following sections of code:

ScreenCap-Error in code- PsychoJS.js

ScreenCap-Error in code - MinimalStim.js

I cannot for the life of me work out what I am supposed to do to fix this. :confused:

I will include the code snippets I am using in the routine to provoke this error. I don’t think I’m doing anything particularly fancy here - EXCEPT I am a creating an object (my continue button) programatically and then referring to it using the Mouse component (sequentially below the code component).


ContinueButton_Y = visual.ButtonStim(win,
    text='Continue', font='Arial',
    pos=(.6, -.4),
    size=[.25, .1], borderWidth=0.0,
    fillColor='darkgrey', borderColor=None,
    color='white', colorSpace='rgb',
    bold=False, italic=False,

#Flags for revealing continue button

boxlist = [YesCheckbox,NoCheckbox]
# initialize the boxes
for box in boxlist:
    box.selected = False # assign a custom attribute to say if this box is currently selected
    box.fillColor = 'lightgray' # reset the color
# control the allowed timing intervals of click events
clickInterval = 0.2 #time between clicks (prevents very fast clicking on and off)
lastClickTime = 0

And then in EACH FRAME:

if mouse_4.isPressedIn(YesCheckbox):
    if t > lastClickTime + clickInterval:  # Debounce
        YesCheckbox.selected = True
        NoCheckbox.selected = False
        print("Clicked in box 1")
        HaveVal = True
if mouse_4.isPressedIn(NoCheckbox):
    if t > lastClickTime + clickInterval:  # Debounce
        NoCheckbox.selected = True
        YesCheckbox.selected = False
        print("Clicked in box 2") 
        HaveVal = True
# set the color of clicked and non clicked boxes
for box in boxlist:
    if box.selected:
        box.fillColor = 'green'
        box.fillColor = 'lightGray'

if HaveVal and not ContButton:
    print("MAKE BUTTON!")



Note my mouse object is set to end routine on ‘Valid Click’ on ‘Clickable Stimuli’: ContinueButton_Y

I am utterly stumped and don’t know how to move forward with this.

Any help or advice would be WILDLY appreciated. <3

Thanks folks!


The error is in the following line

    ContinueButton_Y = new visual.ButtonStim(psychoJS.window, {"text": "Continue", "font": "Arial", "pos": [0.6, (- 0.4)], "letterHeight": 0.05, "size": [0.25, 0.1], "borderWidth": 0.0, "fillColor": "darkgrey", "borderColor": null, "color": "white", "colorSpace": "rgb", "opacity": null, "bold": false, "italic": false, "padding": null, "anchor": "center", "name": "ContinueButton_5"});

I don’t think ButtonStim works online yet.

Hi @wakecarter!

OHYES!!! You’re right! Went back to the ‘crib-sheet’ doco - and, sure enough, there’s a line in there about not using visual.ButtonStim which, I now gather, is what builder refers to as ‘Button’.

Far out! Thanks SO much for pointing this out. I removed all the buttons from my experiment (every page - some generated programmatically, some with quite a bit of validation logic etc… attached) and replaced them with Polygons and - IT WORKS! Wooooo!

Thanks again.


(I now have to figure out why the orientation of the little triangle polygons I’m using instead of buttons is reversed by 180deg in the on-line version as opposed to the local version. Sigh…)

Multiply the angle of rotation by a variable (e.g. rotation) by 1 for Python and -1 for JavaScript. I set this variable in Begin Experiment in a Both code component.


That’s an awseome answer. Thanks so much!!!

So is there anyway I can determine this programmatically thereby keeping the same code-base for both?



Yes. If it’s online it will run the JS code and if it’s local it will run the Py code.