Alert 4210: JavaScript Syntax Error in 'Begin JS Experiment' tab. See 'Line 1: Unexpected token' in the 'Begin JS Experiment' tab

OS : macOS Monterey v. 12.1
PsychoPy version : v2022.1.1
Standard Standalone? (y/n) If not then what?:y
What are you trying to achieve?: I recently got a new computer, downloaded the newest version of PsychoPy, and tried to run an experiment that worked on the previous version of PsychoPy (v2021.2.3). When I ran my experiment, it would start normally asking for the participant and session which I would enter. It switched to the grey starting screen like normal but would then crash, and in the Runner I saw two identical alerts - Alert 4210: JavaScript Syntax Error in ‘Begin JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Begin JS Experiment’ tab - without any other Alerts or Errors.

What did you try to fix it?: I checked all my code added through the Builder to make sure there weren’t any syntax errors in the Python code that would prevent the automatic JavaScript code generation and there was nothing. I did some digging on this alert and saw in several places that the issue was import statements, specifically import random. But, even after removing the import random line and its associated code, I still get this alert, and I assume it is for my other import statements which are ‘import pandas as pd’ and ‘import csv’.
I went back to my old computer to check and make sure the experiment was working in the previous version with all the import statements and it ran without any issue. So, at this point I’m wondering if I should just reinstall the older version of PyschoPy that works for my experiment.

The alert is telling you that this code (importing Python libraries) won’t work online. If you use an earlier version you might not get the alert, but the code still won’t work online.

If you are only working locally then you can ignore the alerts. They shouldn’t stop your experiment running.

1 Like

Oh I understand. Since I’m running it locally I can select Python for my code instead of the default Auto Py->Js, and that worked! Thank you very much.

1 Like

Hello, I hope this message finds you well. I have the same problem that @RebekahSchneider has, but i do want to work it online.
I have tried using the “Math.random” but it doesn’t work. Is there any other solution I can try? I would really appreciate the help.
By the way, the experiment I am working on is the Nback

Have a look at my crib sheet for alternatives to Math.random.

You might find my PM N-Back online demo useful

Thank you for the information @wakecarter