I am trying to make sure the map view is ready when using components before accessing it to zoom to a location, etc. The official way I found to do this was to use the mapView.viewOnReady method as seen in the release notes for version 4.33 here https://developers.arcgis.com/javascript/latest/4.33/ .
However, it seems like 1/10 of the time I load my web application I get the error that viewOnReady is not a function. Is there a better official/more robust way to make sure the map view element is loaded before trying to call this viewOnReady method than the below?
const viewElement = document.getElementById("map-component");
await viewElement.viewOnReady();
Is this a CDN app or npm? It's possible maybe in a CDN app that a network issue might add just enough of a delay for map-components code that defines that method to not load in time, but I hadn't seen that before.
Having components script in the head and user script as last element of the body makes sure this doesn't happen.
I'm using the CDN. I think my scripts were actually above the components in the head, so I moved them down to the body like you suggested. After doing some testing, I will comment back with whether this fixed my problem or not. Thanks for the tip!