Unable to export objects from web module for use in frontend

Hello, I am having trouble exporting things that are not functions. As an example:

In backend/foo.jsw:

export let bar = “baz”;

In some page code:

import {bar} from ‘backend/foo’;

console.log("bar is " + bar); // outputs “bar is undefined”

I am able to export and use functions as expected, but am unable to figure this out. Any help would be appreciated.

1 Like

Wix team,
Could someone please take a look at the question above? I see same behavior.
Is it wrong to try such an export of object? Can object be export only from /public?

Thanks

Are you trying to do that from frontend or backend?

It should work on the backend side. I don’t think it works from the backend to the frontend tough

An object cannot be imported from backend to frontend - or from frontend to backend for that matter.

Frontend code can invoke backend code as web modules. See the article Corvid: Calling Server-Side Code from the Front-End with Web Modules for details.

Thanks for clarification Yisrael. The article you are referring to explains explicitly regarding functions defined at backend and I was missing similar explanation / limitation description for the objects defined in web module.