1

I'm getting an error with almost every Craft project I set up when I try and run any composer command:

Parse error: parse error, expecting `';'' or `'{'' in /path-to-my-project/craft/vendor/craftcms/plugin-installer/src/Installer.php on line 471

This happens with all Craft installations and all composer commands, update, install etc.

We're using a Mac and MAMP

Has anyone seen this before?

1 Answer 1

3

You're running an outdated version of PHP on your command line. Depending on your setup, your terminal may use an OS-provided version of PHP which isn't up to date. The error comes from this line:

private function _path(string $vendorDir, string $cwd, string $path): string

The parser throws this error because of the return type declaration (: string) after the function signature. This feature was only introduced in PHP 7.0, so to get this error you have to be running an older version than that. To find out which version of PHP you're running and where the binary is on your machine, use php -v and which php. You can also check which PHP binary Composer is running with composer -vvv about.

To fix this, install PHP 8.1 or 8.0 on your machine and make sure it comes before the current version in your $PATH so Composer can use it.

1
  • Hi Moritz, thanks for your help. I think that's it, looks like the Mac itself is running 5.6. Ok, I'll try and get that updated.
    – Mark
    Feb 3 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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