Uncaught (in promise) Error at i (wixCodeNamespacesAndElementorySupport.min.js:1)

Hi! I have code to fill a search dropdown on my site which is causing this error sporadically. It does not happen in Preview mode, but it does happen in my live site (sometimes, it does not happen).

I basically call an aggregate on a collection, and then call a get on a referenced collection for each of the retrieved items, wait for them with Promise.all(), and return them. Then I format them as options for my dropdown. The problem seems to happens between the second and third console.log() statements. This code is in my page onReady section.


Here is the code:

import wixData from 'wix-data';

$w.onReady(function () {    

let seriesAggregate;
wixData.aggregate("Mensajes")
    .group("serie")
    .max("fecha")
    .descending("fechaMax")
    .run()
    .then( result => {
        console.log("First then() started.");
        seriesAggregate = result;
        //Obtener informacion de las series
        let series = [];
        result.items.forEach( item => {
            series.push(wixData.get("Series", item._id));
            console.log(item);
        })
        console.log("First then() finished.");
        return Promise.all(series);
    }).then( series => {
        //Agregar información de las series al resultado anterior       
        console.log("Second then() started.");
        let i = 0;
        seriesAggregate.items.forEach( item => {
            item.titulo = series[i].titulo;
            item.orden = series[i].orden;
            i++;
        });
        //Organizar según orden seleccionado en la base de datos
        seriesAggregate.items.sort( (a, b) => { return a.orden - b.orden });
        //Crear opciones para el dropdown
        let options = [{"value": "", "label": "Todos"}];
        options.push(...seriesAggregate.items.map( serie => {
            let ano = serie.fechaMax.getFullYear();
            let mes = serie.fechaMax.toLocaleDateString("es-ES", {month: 'short'});
            return {"value": serie._id, "label": mes + " " + ano + "-" + 
                    serie.titulo};
        }));
        $w('#dropdownSerie').options = options;
        console.log("Second then() finished.");
    });

});

Here’s the error I get in Site Monitor:

"root":{
    "insertId":".........06CI3Ya.6C15d7BgGwLkY2V"
    "timestamp":"2020-06-02T07:29:43.508Z"
    "severity":"ERROR"
    "labels":{
        "siteUrl":"https://www.graciasoberana . org"
        "namespace":"Corvid"
        "tenantId":"d8eae1fc-ddad-4b7c-8645-b7420a6d131c"
        "viewMode":"Site"
        "revision":"909"
    }
    "operation":{
        "id":".........030mQbSfi48IPymQHmyZENo"
        "producer":"/mensajes"
        "first":false
        "last":false
    }
    "sourceLocation":{}
    "jsonPayload":{
        "message":"Error at i (https://static.parastorage . com/services/wix-code-platform/1.425.0/wixCodeNamespacesAndElementorySupport.min.js:1:97416) at XMLHttpRequest.n.onreadystatechange (https://static.parastorage . com/services/wix-code-platform/1.425.0/wixCodeNamespacesAndElementorySupport.min.js:1:97890) at XMLHttpRequest.wrapped (https://www.graciasoberana . org/_partials/wix-bolt/1.5976.0/node_modules/viewer-platform-worker/dist/bolt-worker.js:18:57954)"
    }
    "receiveTimestamp":"2020-06-02T07:29:44.435Z"
}

And here’s the error I get in my browser’s inspect window:

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

Thank you for any help on how to resolve this!

So, it seems the problem is the Promise.all() statement. I decided to go with Promise.allSettled() and the code worked, but now I have a new error. Again, it doesn’t always happen. There is some consistency though. It doesn’t happen the first time I load the page and starts happening after a refresh it for the first time. Again, it only happens in my live site, not in when I preview it.

The new error is:

console.js:35 Cannot read property 'titulo' of undefined
e.<computed> @ ua-parser.js:1

I did some tests and it disappears when I comment the line:

item.titulo = series[i].titulo;

But the property is set in series[i] because I can log it to the console right before. Can it be a problem with the cache?

I noticed I had set cache to manually because I was testing and wanted the site reload everytime. I set the cache to automatically and everything works fine now.

We have the same problem! would love a real fix!