I am going to guess that your basemap is a different spatial reference than your service. When you query against the service, the SR will be the original SR of the service. You can. request the geometries to be converted to match your map like this.
function zoomToLayer(layer) {
// create query from layer
const query = layer.createQuery();
// ask for SR to match the View
query.outSpatialReference = view.spatialReference;
return layer.queryExtent(query).then((response) => {
view.goTo(response.extent)
});
}