Exported code not working.

Hi,

So 3 weeks ago evrything went fine and our company had a 3 week vacation.
Monday i came back to the desk and checked the website,
at first evrything seemed fine until i start using my custom made program.

Now i have been looking what whas wrong and i think i found it, but i don’t get why…

I have a function in the directory:
import { returnValueAndLabel } from ‘backend/global/returnValueAndLabel.jsw’

The following code is inside it:

export function returnValueAndLabel(result){
let emptyData = [{}]
  for (var i = 0; i < result.length; i++) {
    let data = {
      "label": result[i].title,
      "value" : result[i].waarde
    }
    if(i === 0) {
      emptyData = [data]
    } else {
      emptyData.push(data)
    }
  }
  return  emptyData
}

So nothing to fancy,
I use it as followed:

await getData2("vrzbladkleur", event.target.value).then(async res => {

            $w("#rbKleurBlad").options = await returnValueAndLabel(res)
        })

getData looks for data in the database, Returns the values
returnValueAndLabel should add the title and waarde(value) to the options.

Now when i do this i get an error.

wixCodeNamespacesAndElementorySupport.min.js:1 Uncaught (in promise) Error
    at i (wixCodeNamespacesAndElementorySupport.min.js:1)
    at XMLHttpRequest.n.onreadystatechange (wixCodeNamespacesAndElementorySupport.min.js:1)
    at XMLHttpRequest.wrapped (raven.js:376)

Now when i copy the code from :

returnValueAndLabel.jsw

And paste it above the code where i need the function, evrything works fine…

what changed that it doesn’t work anymore?

Kind regards,

kristof.

Not sure this is your problem, but you can’t use both await and .then() together to handle the same Promise. It’s either one or the other:

Either this:

getData2("vrzbladkleur", event.target.value).then(async res => {
    $w("#rbKleurBlad").options = await returnValueAndLabel(res);
})

Or this:

let res = await getData2("vrzbladkleur", event.target.value);
$w("#rbKleurBlad").options = await returnValueAndLabel(res);

BTW - Not sure that this is causing any problems, but…

This is not an empty array:

let emptyData = [{}];

This is actually an array of one item - an empty object.

This is an empty array:

let emptyData = [ ];

Hi Yisrael,

I tried removing the await,
Didn’t work either.

The issue is that it does work when the code is in the same file but not when exporting from another file.

I know the object isn’t empty no worries :D,
It first whas used to empty an arrayofobjects
But it whas less code this way, but didn’t change the name :slight_smile:

@volkaertskristof In what file are you calling returnValueAndLabel() ? Are you calling returnValueAndLabel() from page code? Are you calling returnValueAndLabel() from backend code?

@yisrael-wix
I’m calling it from a page code.
When changing an element (radiobutton)

@volkaertskristof I suspect that a .jsw files are special and cannot be in another folder.

This:

import { returnValueAndLabel } from 'backend/returnValueAndLabel.jsw'

Not:

import { returnValueAndLabel } from 'backend/global/returnValueAndLabel.jsw'

@yisrael-wix

It has bene working for months?
i have a whole bunch of codes
Never had any problem with them.


All .jsw files in subfolders…
They worked fine atleast until 09/07/2021 (i even think until 22/07/2021, since i had a customer that used the web software i wrote and evrything seemed fine)

But when i came back here (02/08/2021) it didn’t worked anymore

I can start copying all the code to all my pages and duplicate them on evry page where i need it, but that isn’t realy how it should work :slight_smile:

@volkaertskristof Are all of those .jsw files called from page code? If not, then you should realize that you can’t call web modules (functions in a .jsw file) from other backend (.js) files. Web modules can only be called from frontend (page) code.

See the article Backend File Types for details.

@yisrael-wix
All .jsw files are called from page code’s,
So in my page code is the code that imports the .jsw file,
this way i should be able to access it.
or this way i could access it untill a few days :slight_smile:

@volkaertskristof Since you say that this was working until a few days ago, I have referred this to Wix Customer Care and this post will be closed.