3

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.

3
  • 1
    Make sure you have the same PHP version on AWS and on your local docker. This would be an issue of "it works on my machine", but then the other way around: it works on beanstalk, but not locally, so fix it locally
    – UnderDog
    Commented Jan 4, 2023 at 5:18
  • The same issue. Did you find a solution? I think some issue with some package?
    – Yevhen L.
    Commented Jan 15, 2023 at 19:56
  • @YevhenL. What I did was to upgrade PHP and Node.js
    – BlackPearl
    Commented Jan 17, 2023 at 11:43

2 Answers 2

9

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.
2
  • what if i have to stick with the current PHP version and I will change version in composer.json file but problem is same again Commented Jun 1, 2023 at 7:53
  • 1
    @GauravMavani if you have PHP 8.0 on the server and PHP 8.0 in your composer.json and still have this error, I guess you have a package which version requires PHP 8.1. Not very pretty but effective way to find out it to delete all dependencies in Composer and add it one by one. So you can find a problem library. And then downgrade the library to the version wich work on PHP 8.0. Commented Jun 5, 2023 at 9:03
0

I just had this error, and after checking my package.json, I found this parameter from my "install" script:

  "scripts": {
    "install": "composer require --dev --ignore-platform-reqs --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer"
  }

Removing it solved my problem, in my case it was not useful, just a bad copy and paste parameter, but in your case maybe it is useful, so double check before removing it

--ignore-platform-reqs

Not the answer you're looking for? Browse other questions tagged or ask your own question.