This error can occur when you had previous code (in drupal 8 f.e.) like this:

$node = $storage->load($nid);

This gives you in drupal 9 the following:

Warning assert cannot load "node" entity with NULL ID

Instead do

if($nid) {
  $node = $storage->load($nid);
  // rest of the script