Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Parse error: syntax error, unexpected identifier "AnsiColorMode" [duplicate]

I got this error while deploying my project on AWS Elastic BeanStalk. I recently pulled my project from github, before that it deploys without issues.

On tracing the error, I found that this line @php artisan package:discover --ansi is where the issue is coming from.

Below is the error:

Generating optimized autoload files

Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover --ansi PHP Parse error: syntax error, unexpected identifier "AnsiColorMode" in /codebuild/output/src155211532/src/vendor/symfony/console/Output/AnsiColorMode.php on line 20 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

This works well on Docker if I delete the composer.lock file and run the command sail composer install.

Please, any help is appreciated.

like image 911
BlackPearl Avatar asked Jun 11 '26 16:06

BlackPearl


1 Answers

If you take a look at line 20 in the file AnsiColorMode.php you will see the following code: enum AnsiColorMode. Enumerations came to PHP in 8.1 version, so I assume your PHP version in the AWS server is less than 8.1.

So you have 2 ways:

  1. Upgrade PHP version on the server to 8.1.
  2. Change PHP to the version which you have on your server in composer.json and run composer update to update vendor libraries. Before that make sure your code is compatible with that version.
like image 57
Sergei Kuraksin Avatar answered Jun 13 '26 05:06

Sergei Kuraksin