"unknown resource" file error when testing locally

URL of experiment: https://pavlovia.org/jacobtfisher/irene-thesis-2

Description of the problem: I’m working on porting an experiment to Pavlovia and I’m getting the “unknown resource error” for my conditions file that it seems many others have been getting as well, but I’ve tried all of the solutions I’ve seen to others’ issues to no avail.

The experiment is a simple text-based experiment with no images or other files referred to in the conditions file. Interestingly, when I run the experiment on Pavlovia itself I am not getting the error–only in the local debug mode. I’ve tried moving the conditions file into the base html folder created by PsychoPy, and have tried a minimal version of the conditions file only containing one line. I’ve also triple checked the CSV for any formatting errors. I’m not sure what is causing the debug mode to fail.

Any thoughts?

2 Likes

Hi Jacob,

I’ve had the same issue. As far as I understand the library (I’m not fluent in javascript), upon running the experiment locally a “ServerManager” instance will be created that is responsible for downloading resources and saving them in a private “_resource” variable. For some reason, this doesn’t happen for some resources like a local conditions file when you run in local debug mode. As a workaround that works for me, you may pass resources like image stimuli and conditions files to the PsychoJS instance at the beginning of the experiment when the start() method is called.

psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [{name: ‘Trials.csv’, path: ‘./resources/trialTypes.csv’}]
});

So I had to add the part beginning with “resources: …”.

Hope that helped.

Cheers,
Alex

1 Like

Hi all,

I find myself in the same situation. I’m able to run the experiment on Pavlovia, but not in the local debug mode. I am loading conditions from an xlsx file (ConditionsMat.xlsx) placed in my resources folder… but the debugger fails loading this file:

Unfortunately we encountered the following error:

  • when importing condition: ConditionsMat.xlsx
  • when getting the value of resource: ConditionsMat.xlsx
  • unknown resource

I tried the workaround suggested above, but no avail:

psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [{name: ‘ConditionsMat.xlsx’, path: ‘./resources/ConditionsMat.xlsx’}]
});

Does anyone have a suggestion on how to sort this out? This would really make debugging so much faster!

Thank you!!
Nicola

1 Like

Same issue here, resources specified in custom (py+JS) code remain unknown. (PsychoPy 2020.1.3) Online they seem to work.

But how do you add the resources line in Builder? It doesn’t expose things like calling the start() method, right? I’d kinda hate to go tweaking the .js file after it’s been created, especially since that means tweaking it after every sync.

Yes, you have to adjust the source code manually. I actually stopped trying to get experiments run via pavlovia. I’m using PsychoPy Builder only for getting the experimental structure right and then I simply do the rest manually. I also managed to get everything run on my own server, although Javascript is a real hassle.

Are you sure that path and filename are correct?

Hi!

turns out I misspelled the file name! I thought I triple-checked … but I should have known better.
I can confirm that it loads the file properly!!

Thanks!

I do believe that this is a flaw in the way PsychoJS is currently designed to work. From the documentation:

By default, PsychoJS downloads from the pavlovia.org server all the resources … at the start of the experiment.

This is indeed true on Pavlovia, but does not work in local debug mode, and in fact, cannot work the way it is currently designed.

One workaround, as mentioned in the documentation, is to load resources manually by editing the .js file of the experiment (found in the html folder). Here is what it looks like in the documentation:

psychoJS.start({
  expName,
  expInfo,
  resources: [
    // relative path to index.html
    { name: 'trialTypes_A.xls', path: 'trialTypes_A.xls' },
    // absolute path:
    { name: 'trialTypes_B.xls', path: 'http://a.website.org/a.path/trialTypes_B.xls' }
  ]
});

The drawback to this workaround is that it has to be redone every time the experiment is updated and a new .js file is generated.

Another workaround, mentioned here, is to blank the output folder in experiment settings. The drawback to this workaround is that Pavlovia does not support a blank output folder, so this will only work in local debug mode, and has to be changed back before publishing to Pavlovia. Maintaining two copies of the output folder is also problematic.

The workaround that I am using is simply to fix the bug that causes this problem in the first place, by editing the following PsychoPy code file: [python-package-directory]/psychopy/experiment/flow.py:

@@ -298,7 +298,7 @@
                                   "expInfo: expInfo,\n")
         # if we have an html folder then we moved files there so just use that
         # if not, then we'll need to list all known resource files
-        if not self.exp.htmlFolder:
+        if 1: #not self.exp.htmlFolder:
             script.writeIndentedLines("resources: [\n")
             script.setIndentLevel(1, relative=True)
             code = ""

And then restarting PsychoPy and re-generating the HTML for the experiment.

The way PsychoJS is currently designed, when running on Pavlovia, it makes an API call to get the list of files in the html/resources folder. PsychoJS needs to implement the same API in the local environment for this to ever work.

The silly thing is that PsychoJS already has the capability to pre-load the resources list at compile time, but this is normally turned off - except when the output folder is blank. I am not sure why an API is used on Pavlovia instead of just pre-loading this list, but for now, it makes more sense to simply pre-load the list at compile time in all cases, which is what the simple 1-line code change above does.