Problem on heroku however everthing works locally

I get this error on a subpage on heroku. However the same snippet works fine on the homepage. It also works without problems when run locally.

Is this a problem with rights on the server?

Does the image exist at all on that subpage? This is an error that typically appears if you call a method - in this case url() - on a non-existing object.

NEVER call a method on an object without making sure the object exists. Use an if statement to check this:

if($image = $page->hero_image()->toFile()):
  // do stuff

On a side note: Your if-statement re. tags and hero_image don’t have any effect. Replace the hero-image check with the above and if you want to check if there are any tags:

$tags = $page->tags()->split();
if(!empty($tags)) {
  // do stuff


  // do stuff

It exists, at least when running locally it can find the image.

The url of the image locally is /content/page/filename.jpg
I can also find the image on the server with that url

Edit: Thanks for the feedback on the if statements!

Well, have you checked the permissions of that particular file on the server? Does it only happen on that particular page?