Type Error: Resource is not an object, evaluating surveyID in resource

URL of experiment:
https://run.pavlovia.org/IsabelLuet/emotprocess

Description of the problem:

Hi,
I am trying to get my experiment to work online and I get the following error in safari:

In the developer the error looks as follows:

On chrome, I get this error

In my experiments I loop through playing videos in the spreadsheet. When instead of looping through the videos, I specify the video that is meant to be played, this also happens when the location of that video is either in my main folder or in the resource folder. It also happens when I load the stimuli at the beginning in code in the psychoJs.start {}.

What can I do to solve this issue?

When I put the experiment online, I also get the pop up that the project root folder is not specified, but with a simpler version of this experiment I was able to pilot it.

Thank you for your help!

Best, Isabel

I solved the root folder problem by clicking on the i sign with a little world symbol in the top right panel next to where you would sync your study online. This allows you to set the root folder which as far as I understand should be your main project folder of your study as per this Launch your study on Pavlovia.org — PsychoPy v2023.1.0

Are you still getting errors mentioning surveyId? I thought it was solved three days ago.

Yeah I am still getting the same error

This is still happening. I made an entire new experiment, and build it bit by bit, trying to test out where things go wrong. It all worked with a reduced number of files (only sad movie files) of my final experiment. It played the movies and downloaded them at the start of the test run. Then I added some more files (this time happy movie files) and it gives me the same error. I then tried to change what I was referencing back to where it had worked, but this does not work.

Good afternoon,

Could you regenerate your experiment with PsychoJS version 2023.1.1? That should do the trick.
I have not had the opportunity to back-port the fix to 2023.1.0 just yet, regrettably.
Cheers,

Alain

How do I change the version? I created a new experiment today, which I pushed online, to try and figure out the issue. When I check the version on my dashboard it is 2022.2.5, automatically.

Hi Alain,

Version 2022.2.5 is the current version according to Installation — PsychoPy v2023.1.0 and the latest version available from Releases · psychopy/psychopy · GitHub is 2023.1.0. Please could you update the Github page if 2023.1.1 has been released?

1 Like

Hi, thanks for your help! Is there any indication for when PsychoJS version 2023.1.1 will be released?
Cheers, Isabel

Some of the fixes created new bugs which are hopefully being sorted today. Barring anything new being discovered, hopefully it will be released early next week.

Hi, still getting this error:
Unfortunately we encountered the following error:

  • when preparing resources for experiment: app_sof_s1
  • TypeError: Cannot use ‘in’ operator to search for ‘surveyId’ in n_back/n_back_1.png

Try to run the experiment again. If the error persists, contact the experiment designer.

with 2023.1.1

Thanks

I’d hoped that bug would be fixed. Can you preload your stimuli via Experiment Settings/Online or in a code component instead of using a Resource Manager component?

Thanks, eventually I was able to use it without getting the error.

What did you have to do?

Hard to say, I’ve tried so many things…
I suspect it was related to the order in which I added the components to the routine but I am unsure.

Just wanted to put it out there, that I got a similar problem fixed by disabling the “resource manager” component!

I am a new user, so I cannot “reply” to a user, but hopefully since wakecarter seems to know something about this bug, someone can tag them?

I thought I would explain what I found.

Looking at the code for the ServerManager.prepareResources() call (psychojs/ServerManager.js at main · psychopy/psychojs · GitHub) it looks like this from lines 505-519:

// convert those resources that are only a string to an object with name and path:
for (let r = 0; r < resources.length; ++r)
{
	const resource = resources[r];
	if (typeof resource === "string")
	{
		resources[r] = {
			name: resource,
			path: resource,
			download: true
		}
	}
}

for (let { name, path, download } of resources)
{
...

However, when I look at the code for the “same” file loaded by my online Pavlovia experiment the code contains extra lines that seem related to “surveys”:

// pre-process the resources:
for (let r = 0; r < resources.length; ++r)
{
	const resource = resources[r];

	// convert those resources that are only a string to an object with name and path:
	if (typeof resource === "string")
	{
		resources[r] = {
			name: resource,
			path: resource,
			download: true
		};
	}

	// deal with survey models:    <--- THIS DOES NOT APPEAR IN GITHUB
	if ("surveyId" in resource)    <--- resource is still a string here. NEED TO USE resources[r]
	{
		// survey models can only be downloaded if the experiment is hosted on the pavlovia.org server:
		if (this._psychoJS.config.environment !== ExperimentHandler.Environment.SERVER)
		{
			throw "survey models cannot be downloaded when the experiment is running locally";
		}

		// we add a .sid extension so _downloadResources knows what to download the associated
		// survey model from the server
		resources[r] = {
			name: `${resource["surveyId"]}.sid`,
			path: resource["surveyId"],
			download: true
		};
	}

	// deal with survey libraries:
	...etc REMOVED EXTRA code...
}

for (let { name, path, download } of resources)

The bug is that this code:

// deal with survey models:
if ("surveyId" in resource)

Is using the in operation on the original resource variable…which is a string sometimes (such as when using a static component).

I think that all this extra “survey” stuff must have been added by someone (e.g. pavlovia?), as it is not found in the github PsychoJs code.

Some possible fixes for this bug would be:

  • Move this special “survey” stuff into the for loop at L519 from the original code.
    • I.e. leave the first for loop that converts string resources to object resources as-is. And then put this new for in the for ... of loop.
  • Make sure it is using a resource variable that is an object (so that things like "surveyId" in resource work). Alternatively, these checks could act on resources[r], which is definitely an object.

Anyway, I agree…I don’t think there is anyway to make the static component work until this bug is fixed.

Hopefully you might know who to ask to fix this?

The root of the problem is that, if you have a component which handles resources (such as a :static: Static component or a :resource_manager: Resource Manager component), then resources for components aren’t loaded at the start because these components are handling them instead. Because a :survey: Survey’s ID is considered a resource, it’s also removed from this list.

I’ll look into adding some filtering such that Survey ID’s are exempt from this rule, in the meantime the best way to go about it is probably to export your Survey as a JSON file and specify that file in the “Additional resources” section of Experiment Settings.

A post was split to a new topic: Downloading resources in code