$w(...).onReady is not a function in Live only, not preview.

Hello,

I am getting an error in my live site that says $w(…).onReady is not a function, and references my dataset’s onReady. The code works as expected in preview mode, but breaks when I publish and go live. I have checked the database permissions already, and set the dataset to both ‘read-only’ and’read-write’, to no avail. I have also checked that the databases are all synced to live. I am not sure why my code would work exactly as expected in preview mode and not in live. Here is the page code for the lightbox where this error occurs.

import wixWindow from 'wix-window';
import wixData from 'wix-data';

$w.onReady(function () {
    $w('#repeater1').hide();

    $w("#dataset1").onReady(() => {
 let clientEmail = wixWindow.lightbox.getContext();
 let cartDisplay = [];

        wixData.query('CodePacks')
            .hasAll('packName', clientEmail)
            .find()
            .then((results) => {
 let cartCodes = results.items[0].incCodes;
                console.log(cartCodes);

 let total = $w('#dataset1').getTotalCount()
                $w('#dataset1').getItems(0, total)
                    .then((codeResults) => {
 let codeIds = codeResults.items;
 for (let i = 0; i < cartCodes.length; i++) {
 for (let j = 0; j < total; j++) {
 if (codeIds[j]._id === cartCodes[i]) {
                                    cartDisplay.push(codeIds[j]);
                                }
                            }
 //$w('#dataset1').setFilter(wixData.filter().hasAll('_id', cartCodes[i]));
 //cartDisplay.push($w('#dataset1').getCurrentItem());

                        }
                        console.log(cartDisplay);
                        $w('#repeater1').data = cartDisplay;
                        updateRepeater();
                    });

            });
    });
});

export function updateRepeater() {

    $w("#repeater1").show();
    $w("#repeater1").forEachItem(($item, itemData, index) => {
        $item("#text17").text = itemData.codeName;
    });

}

Any help would be greatly appreciated!

Thanks,

Stephen

$w.onReady(function () {
$w("#dataset1").onReady(() => {
    $w('#repeater1').hide();

Dataset - Velo API Reference - Wix.com

Thanks for the reply. I had actually already tried commenting out the repeater hide, and just tried moving it into the dataset onready. I’m still running into the same issue. Thanks, though!

@stephenmarold When you open up the browser console, do you get any slow connection warnings? In the network tab, is it successfully connecting to filesusr?

@skmedia There have been no slow connection warnings, and all I’m seeing in the network tab is “recording network activity…”

@stephenmarold The network tab doesn’t display anything unless it’s open, so hit f5 to reload with the network tab open.

@skmedia Yes, it is successfully connecting to the fileuser.
However, I am now getting an "Uncaught (in Promise) error instead of the “not a function” error. Note that the code still works as expected in Preview mode.

@stephenmarold Post a screenshot of your errors, please.

@stephenmarold

One quick question, as you are saying that your datasets onReady function is not working.

Is the dataset that you have on your page called #dataset1 in the properties id or shown on the top of it when you click or hover over the dataset icon on your page?

Or have you called it something else as this possibly could be a simple reason as to why you are getting the error.

Also, you are not constant with your marks on your dataset and repeater for example, however that shouldn’t make a difference and cause this issue.

$w("#dataset1").onReady(() => {
$w('#dataset1').getItems(0, total)

$w('#repeater1').data = cartDisplay;
$w("#repeater1").show();