I got this error deploying a Drupal site using version 9.4.2:

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in /var/www/html/vendor/symfony/finder/Finder.php on line 57

Solution

This can be caused by using the wrong actual PHP version with the PHP-version stated in composer. So, fix this :-)

Other possible solutions

Added this in the composer.json

"config": {
        "platform": {
            "php": "7.4.21"
         }
   }

Then run composer update

This downgraded psr/log to a lower version from 2.0 and resolved the issue.

 

Saved you some valuable time?

Buy me a drink 🍺