use entityQuery within a Block plugin
There are brackets missing:

$nids = $query-&gt;execute();


In my block this works:

 public function build() {
   $query = \Drupal::entityQuery('node');
   $nids = $query-&gt;execute();

  $build = [
   '#theme' =&gt; 'item_list',
   '#items' =&gt; $nids,
  ];

 return $build;
}