There are brackets missing:
$nids = $query->execute();
In my block this works:
public function build() {
$query = \Drupal::entityQuery('node');
$nids = $query->execute();
$build = [
'#theme' => 'item_list',
'#items' => $nids,
];
return $build;
}