I have been confused by a strange phenomenon.

I use the code below to export a batch of images to Drive, but I cannot export successfully every time, sometimes here comes an Error message Cannot read property 'length' of undefined after almost 10 min awaiting, so I want to test on whether the list of imageCollection is empty or not, then I print the list out, then it works! But sometimes it still dosen't work, and I turn to comment all 'print', it works in some cases! Finally, I just try to export images to Drive with or without 'print'. It works randomly!

My Internet connection is available and I think 'print' may have no contribution to my code.

what happened?

export_imgCollection_raw2(L4578_delta, roi_boundingBox, stationName);

function export_imgCollection_raw2(imgCol, region, stationName){
  var indexList = imgCol.reduceColumns(ee.Reducer.toList(), ["id_info"]).get("list");
  // print('indexList',indexList)
  indexList.evaluate(function(indexs) { 
    for (var i=0; i<indexs.length; i++) { 
      var image = ee.Image(imgCol.filter(ee.Filter.eq("id_info", indexs[i])).first());
      var id ='delta_' + stationName + '_' + String(indexs[i]);
        image: image,
        folder: 'delta',
        description: id,
        fileNamePrefix: id,
        region: region, 
        scale: 30, 
        crs: "EPSG:4326", 
        maxPixels: 1e13, 
        fileFormat: 'GeoTiff',

1 Answer 1


It sounds like you are encountering an error of some sort when computing indexList. When this happens, evaluate will call your function(indexs) with indexs undefined, and a second argument (which your code is currently ignoring) containing the error message.

You can check for an error with a little extra code in the function:

  indexList.evaluate(function(indexs, error) { 
    if (error) {
      print("Failed to evaluate indexList", error);
    for (var i=0; i<indexs.length; i++) { 
      // ... rest of the code you already had ...

In this way, you won't get the unhelpful "Cannot read property 'length' of undefined" message (which came from i<indexs.length trying to work while indexs isn't an array), but instead see the original error message from the server.

  • Thank you, Kevin, I have tried your method and got a message: Invalid JSON:
    – Jiawei Wei
    Jun 13, 2021 at 10:45
  • Sometimes here comes an error: Computation timed out. So I think the reason is on the unstable connection between Cilent and Cloud of earth engine? I just run my code once again without any change, it works randomly. So strange it is.
    – Jiawei Wei
    Jun 13, 2021 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.