Errors are part of coding. This guide helps you identify, understand, and fix common Earth Engine problems quickly so you can get back to your analysis.
What you'll learn
- Interpret common error messages.
- Fix client vs. server object issues.
- Resolve scale and memory problems.
- Debug step-by-step with print statements.
- Know when to ask for help (and how).
The debugging mindset
- Read the error carefully. The message often tells you exactly what's wrong.
- Isolate the problem. Comment out code until it works, then add back line by line.
- Print intermediate results. Use
print()to inspect objects. - Simplify. Test on a tiny area or single image first.
- Search. Others have likely had the same problem.
Common errors and fixes
1. "X is not a function"
image.normalizedDifference is not a function
Cause: The variable isn't what you think it is (maybe null or wrong
type).
Fix:
// Debug: Check what the variable actually is
print('Type of image:', image);
// Common cause: .first() on empty collection
var collection = ee.ImageCollection('...')
.filterDate('2023-01-01', '2023-01-02')
.filterBounds(roi);
print('Collection size:', collection.size()); // Check if empty!
var image = collection.first();
2. "Image.select: Pattern 'X' did not match any bands"
Image.select: Pattern 'B5' did not match any bands.
Cause: Wrong band name for this dataset.
Fix:
// Debug: Print actual band names
print('Available bands:', image.bandNames());
// Landsat 8 SR uses SR_B5, not B5
var nir = image.select('SR_B5'); // Correct for Landsat 8 SR
3. "User memory limit exceeded"
User memory limit exceeded.
Cause: Too much data being processed at once.
Fix:
// 1. Reduce the area
var smallRoi = roi.buffer(-5000); // Shrink your ROI
// 2. Increase scale (lower resolution)
var result = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: roi,
scale: 100, // Was 30, now 100
maxPixels: 1e9
});
// 3. Use bestEffort
var result = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: roi,
scale: 30,
bestEffort: true // Auto-adjust scale if needed
});
4. "Cannot add an ee.Image to a number"
Cannot add an ee.Image to a number
Cause: Mixing client and server objects with JavaScript operators.
Fix:
// Wrong: Using + with server objects
var bad = image.add(10 + ee.Number(5));
// Right: Use ee methods
var good = image.add(ee.Number(10).add(5));
5. "Computation timed out"
Computation timed out.
Cause: The computation is too complex or the area too large.
Fix:
// 1. Export instead of print for large results
Export.image.toDrive({...});
// 2. Reduce collection size
var filtered = collection
.filterDate('2023-06-01', '2023-06-30') // Shorter date range
.filter(ee.Filter.lt('CLOUD_COVER', 20)); // Fewer images
// 3. Simplify the computation
// Instead of 100 bands, select only what you need
var simple = image.select(['SR_B4', 'SR_B5']);
6. "Dictionary does not contain key: X"
Dictionary does not contain key: NDVI_mean
Cause: The property or key you're accessing doesn't exist.
Fix:
// Debug: Print all keys
var result = image.reduceRegion({...});
print('Keys:', result.keys());
// Make sure you're using the correct property name
var mean = result.get('SR_B5'); // Use actual key name
7. Empty or null results
Cause: Filters removed all data, or the geometry doesn't overlap.
Fix:
// Check collection size at each step
var step1 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2');
print('All images:', step1.size());
var step2 = step1.filterDate('2023-06-01', '2023-08-31');
print('After date filter:', step2.size());
var step3 = step2.filterBounds(roi);
print('After bounds filter:', step3.size());
// If 0, check your ROI location and date range
Client vs. Server: Quick reference
| Client (JavaScript) | Server (Earth Engine) |
|---|---|
var x = 5 |
var x = ee.Number(5) |
x + 3 |
x.add(3) |
[1, 2, 3] |
ee.List([1, 2, 3]) |
for (var i=0; ...) |
collection.map(function) |
if (x > 5) |
ee.Algorithms.If(x.gt(5), ...) |
Rule: Once you're in server-land (ee. objects), stay there. Don't try
to use
JavaScript operators on Earth Engine objects.
Debug with print()
Strategic print statements are your best friend:
// Print at each step to find where things go wrong
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2023-06-01', '2023-08-31')
.filterBounds(roi);
print('1. Collection size:', collection.size());
print('2. First image:', collection.first());
print('3. Band names:', collection.first().bandNames());
var ndvi = collection.map(function(img) {
return img.normalizedDifference(['SR_B5', 'SR_B4']);
});
print('4. NDVI collection:', ndvi.first());
var composite = ndvi.median();
print('5. Composite:', composite);
Scale matters!
Earth Engine resamples everything to match your specified scale. Wrong scale = wrong results.
// Always specify scale in reduceRegion
var stats = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: roi,
scale: 30, // Match your data's native resolution!
maxPixels: 1e9
});
// Common native resolutions:
// Landsat: 30m
// Sentinel-2: 10m (visible), 20m (red edge), 60m (atmospheric)
// MODIS: 250m, 500m, 1000m
// DEM (SRTM): 30m
Pro tips
- Use the Inspector tab to click on map pixels and see values.
- Check the Docs tab for function signatures and examples.
- Search GIS StackExchange for your error message.
- Ask on the GEE Developers Forum with a minimal reproducible example.
- When stuck, simplify: one image, small area, fewer bands.
When to ask for help
Before posting a question:
- ✅ Searched for the error message
- ✅ Read the function documentation
- ✅ Created a minimal example that reproduces the error
- ✅ Included the full error message
- ✅ Described what you expected vs. what happened
Quick self-check
- What's the first thing to do when you get an error?
- How do you check if a collection is empty?
- What causes "User memory limit exceeded"?
- Why can't you use
+withee.Number?