3

Anyone succeeded in upgrading from Craft 3 to Craft 4 ?

Before staging the changes on our dev server, I tried it locally without success. Although it seems pretty strait forward, I updated all plugins (2 of them are not compatible, so I took them off for now as we're not using it yet on dev - reCaptcha and Kint), took care of all deprecation warnings, did the project-config/rebuild and change craftcms/cms to ^4.0.0 and obviously move to PHP 8. Here's a sampler of my installation.

enter image description here

Next step would be composer update, but can't pass this step with success. See other picture of all conflicts... As usual, your input would be greatly appreciated !

Sylvain

enter image description here

1 Answer 1

4

To upgrade to Craft 4, you'll need to make sure that Composer is allowed to upgrade all of your plugins to their Craft 4 compatible releases as well. This is done by manually editing your installed plugins' version constraints in your composer.json file.

The reason why this is necessary is that most plugins are bumping their major version for the Craft 4 compatible release – for example, Feed Me is going from version 4.x to 5.x for the Craft 4 compatible release – and in most cases, Composer isn't able to upgrade an installed package to a new major version automatically. This is due to version constraints in the composer.json file, and in general this is a good thing – major version upgrades often include breaking changes, and those constraints prevent Composer from accidentally upgrading to a version that could break your application.

As an example: in order to allow Composer to update Feed Me to the Craft 4 compatible version, you'll need to change the craftcms/feed-me package's version constraint from this:

"require": {
    ...
    "craftcms/feed-me": "4.5.1"
    ...
  },

To this:

"require": {
    ...
    "craftcms/feed-me": "^5.0.0"
    ...
  },

You'll need to step through each of your installed plugins to find the version you need to add to your composer.json file. The easiest way to do that is probably visiting the new "Craft 4 Upgrade" utility, which is found under Utilities -> Craft 4 Upgrade inside the Control Panel. This utility is available in Craft 3.7.39 or later, and lists all the latest, compatible versions for any and all plugins installed.

Note that some plugins may still be in beta for their Craft 4 compatible release. If so, make sure to add the -beta part to the version constraint for that plugin as well, i.e. so it looks like this:

"require": {
    ...
    "nystudio107/craft-retour": "^4.0.0-beta"
    ...
  },

After making sure that all plugins have a Craft 4-compatible version constraint declared in your composer.json file, run composer update.

If that didn't work and you're still getting Composer errors – and some of your plugins' versions are in fact beta releases – try adding the following rules to your composer.json file:

"minimum-stability": "beta",
"prefer-stable": true,

Then try composer update again.

Also note the official Craft 4 upgrade guide.

3
  • 1
    Nice, this make a huge difference and I "almost" managed to make it to work completely. Well I took off one plugin for now (Image Optimizer) which was giving me a lot of pain in ... and all the rest is fine. Now a few minor Twig changes and I should be on my way to complete migration. Thank you Pal !!! May 10, 2022 at 19:50
  • 1
    this really should be added to the official documentation for everyone who's not so composer savvy. May 17, 2022 at 14:13
  • Agreed, I even remembered this was the case from reading it a while ago, but was still confused when I went to actually update. This part of the documentation: "Edit your project’s composer.json to require...Craft-4-compatible plugins..." is frustratingly vague. It would be great if that linked out to an explanation of the (cumbersome but understandably necessary) required step of manually updating each plugin's major version in your composer.json file.
    – Nate Beaty
    Aug 1, 2022 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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