Error in my JS code prevents sync to Pavlovia

URL of experiment: https://run.pavlovia.org/Crible/matcher_task

Description of the problem:
Hi, I created an experiment with a task where people have to type in words. I copied the code component from a previous experiment that worked online.

When I first created the project on Pavlovia it synchronized, but when I synced it for a second time to get the .html extension, I got the following error message:

Traceback (most recent call last):
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1221, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, 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 236, in writeScript
entry.writeInitCodeJS(script)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py”, line 140, in writeInitCodeJS
thisCompon.writeInitCodeJS(buff)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\text_init
.py", line 174, in writeInitCodeJS
depth = -self.getPosInRoutine()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components_base.py”, line 565, in getPosInRoutine
routine = self.exp.routines[self.parentName]
KeyError: ‘typeNum’

“typeNum” is the name of the first routine that has the code component. This stops the experiment from syncing and it’s not working when I try to pilot it online (403 Forbidden).
I assume there’s a problem in my code that prevents it to work. I have two routines with the same code component, only in the second I adapted the name of a text component. Here’s the first (with a text component called “text”):

Begin routine:

modify = false;
text.text = '';

Each Frame:

let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) {  // at least one key was pressed
  textAdd = theseKeys[theseKeys.length-1]; 
  }

if (textAdd === 'return') {
    textAdd = '';  // Add nothing
    continueRoutine = false;  // End routine (if that is what you want)
} else if (textAdd === 'space') {
    textAdd = ' ';  // Add a space
} else if (textAdd === 'backspace') {
    text.text = text.text.slice(0, -1);
    textAdd = undefined;
} else if (['lshift', 'rshift'].includes(textAdd)) {
    modify = true;
} else if (textAdd !== undefined) {
    if (modify) {
        text.text = text.text + textAdd.toUpperCase();
        modify = false;
    } else {
        text.text = text.text + textAdd
    }
    textAdd = undefined;
}

End Routine:

psychoJS.experiment.addData("typedNum", text.text)
text.setText('')  // empty the onscreen text ready for next input

And here’s the second code in the second routine (with a text component called “text_3”):

modify = false;
text_3.text = '';
let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) {  // at least one key was pressed
  textAdd = theseKeys[theseKeys.length-1]; 
  }

if (textAdd === 'return') {
    textAdd = '';  // Add nothing
    continueRoutine = false;  // End routine (if that is what you want)
} else if (textAdd === 'space') {
    textAdd = ' ';  // Add a space
} else if (textAdd === 'backspace') {
    text_3.text = text_3.text.slice(0, -1);
    textAdd = undefined;
} else if (['lshift', 'rshift'].includes(textAdd)) {
    modify = true;
} else if (textAdd !== undefined) {
    if (modify) {
        text_3.text = text_3.text + textAdd.toUpperCase();
        modify = false;
    } else {
        text_3.text = text_3.text + textAdd
    }
    textAdd = undefined;
}
psychoJS.experiment.addData("typedWord", text_3.text)
text_3.setText('')  // empty the onscreen text ready for next input

Can you spot any error there that would explain why the project won’t sync?
Or is it some other kind of error?

Thanks a lot for your help!

Do you perhaps have a component called typeNum as well as a routine?

text_3.text = '';
text_3.setText('')

I would recommend setting at a space rather than completely empty.

Hi @wakecarter , thanks for the reply!
I don’t have a component called typeNum. However I did add the space in the code as you recommended and it’s working now! Many thanks.