JS Compile TypeError: __str__ returned non-string (type NoneType)

Hi everyone, following error on a task working correctly under psychopy. Occurs when I try to compile JS or create html. PsyPy 21.1.0 on Win 10. Only occurring on this task, others I have (created under earlier versions of PsyPy 2020.x.x) compile to JS fine. Guessing there is a JS code bug somewhere, either my own or this release? Any ideas? Thanks in advance.


Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 759, in fileExport
    target="PsychoJS")
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 73, in generateScript
    compileScript(infile=exp, version=None, outfile=filename)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 242, in compileScript
    _makeTarget(thisExp, outfile, targetOutput)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 214, in _makeTarget
    script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 265, in writeScript
    self_copy._currentRoutine.writeRoutineBeginCodeJS(script, modular)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py", line 287, in writeRoutineBeginCodeJS
    thisCompon.writeRoutineStartCodeJS(buff)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\code\__init__.py", line 231, in writeRoutineStartCodeJS
    if len(str(self.params['Begin JS Routine'])) and not self.params['disabled']:
TypeError: __str__ returned non-string (type NoneType)

Hi I’m getting a similar error on v2021.1.1 when trying to export my experiment to Pavlovia. This runs fine in the builder

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1320, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 759, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript
_makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in _makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 265, in writeScript
self_copy.currentRoutine.writeRoutineBeginCodeJS(script, modular)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py”, line 287, in writeRoutineBeginCodeJS
thisCompon.writeRoutineStartCodeJS(buff)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\code_init
.py", line 231, in writeRoutineStartCodeJS
if len(str(self.params[‘Begin JS Routine’])) and not self.params[‘disabled’]:
TypeError: str returned non-string (type NoneType)

I’m not sure whether it’s a bug, or something wrong in my code… but I notice that there have been several reports lately of unhandled internal error when exporting to Pavlovia. I would really appreciate any assistance!

Thank you!

This indeed sums like a bug related to If statements, as hinted also by Pk403

I’ve isolated the problem to an if statement in my code. If I eliminate this if statement in the Js window, I don’t get the unhandled error.
I even tried the simplest statement possible:
Py
a=1
if a==1:
print(1)

Js
a = 1;
if ((a === 1)) {
console.log(1);
}

If this line is in (or any other If type statement), I can’t compile the Js nor export to Pavlovia. As soon as I eliminate this piece of code I don’t get the error. Any explanations for this? Solutions?

Looks like Jon is on it and the temporary solution is here: Errors Pushing to Pavlovia PsychoPy 2021.1.0

1 Like

Thanks! this drove me nuts yesterday. I see a new release is available today

Hi Nicola, yes this hack fixed the issue for me. Hopefully sorted in the new release.

For others coming to this you can download 2021.1.2 now :slightly_smiling_face:
Sorry for the new-release-hiccups!