FieldCondition in an EntityQuery for media is causing a website error This entityQuery in a theme preprocess function in Drupal 8 is working great:

$query = \Drupal::entityQuery('media')
    -&gt;condition('status', 1)
$result = $query-&gt;execute();


But as soon as I add this fieldCondition for a boolean field, I get a website error:

$query = \Drupal::entityQuery('media')
    -&gt;condition('status', 1)
    -&gt;fieldCondition('field_flagged', 'value', '1', '=');
$result = $query-&gt;execute();


What is wrong in the above code?
There's no fieldCondition method, condition works for all fields:

$query = \Drupal::entityQuery('media')
  -&gt;condition('status', 1)
  -&gt;condition('field_flagged', 1);
$result = $query-&gt;execute();