Step-by-step guide to upgrade to Strapi 5
The latest major version of Strapi is Strapi 5.
The present page is meant to be used as step-by-step instructions for upgrading your Strapi v4 application to Strapi 5.
Your Strapi v4 application is already running on the latest v4 minor and patch version. If it's not, run the upgrade tool with the minor
command to reach it: npx @strapi/upgrade minor
.
Step 1: Get ready to upgrade
Before getting into the upgrade process itself, take the following precautions:
Backup your database.
If you are using SQLite with the default configuration (the default database provided with Strapi), your database file is named
data.db
and is located in the.tmp/
folder at the root of your Strapi application.If you are using another type of database, please refer to their official documentation (see PostgreSQL docs and MySQL docs).
If your project is hosted on Strapi Cloud, you can manually create a backup.
Backup your code:
- If your code is versioned with git, create a new dedicated branch to run the migration.
- If your code is not versioned with git, create a backup of your working Strapi v4 code and store it in a safe place.
Ensure the plugins you are using are compatible with Strapi 5.
To do so, list the plugins you are using, then check compatibility for each of them by reading their dedicated documentation on the Marketplace website.
Step 2: Run automated migrations
Strapi provides a tool to automate some parts of the upgrade to Strapi 5: the upgrade tool.
Run the upgrade tool.
npx @strapi/upgrade major
The command will execute the update and installation of the dependencies of Strapi 5, and run the codemods to handle some of the breaking changes that come with Strapi 5.
The codemods will handle the following changes:
Codemod name and GitHub code link Description comment-out-lifecycle-files Comment out lifecycles files in favor of Document Service Middlewares dependency-remove-strapi-plugin-i18n Remove the i18n plugin dependency as i18n is now integrated into the core of Strapi dependency-upgrade-react-and-react-dom Upgrade the react and react-dom dependencies dependency-upgrade-react-router-dom Upgrade the react-router-dom dependency dependency-upgrade-styled-components Upgrade the styled-components dependency deprecate-helper-plugin Partly handle migrations from @strapi/helper-plugin
entity-service-document-service Partly handle the migration from the Entity Service API to the new Document Service API s3-keys-wrapped-in-credentials Wrap the accessKeyId
andsecretAccessKey
properties inside acredentials
object for users using theaws-s3
providersqlite3-to-better-sqlite3 Update the sqlite dependency to better-sqlite3 strapi-public-interface Transform @strapi/strapi
imports to use the new public interfaceuse-uid-for-config-namespace Replace string dot format for config get/set/has with uid format for 'plugin' and 'api' namespace where possible utils-public-interface Update utils to use the new public interface
If you develop Strapi plugins, other codemods handle some aspects of the helper-plugin deprecation. See the related breaking change for more information.
Go over the changes made by the upgrade tool to check if you have to manually complete some code updates:
Look for
__TODO__
automatically added to your code by the codemods. Some of them might have been added while migrating from the Entity Service API to the new Document Service API introduced in Strapi 5.👀 Document Service APIAdditional information about the Document Service API can be found in the breaking change entry description, the specific migration guide, and the API reference.
Step 3: Check and handle manual upgrades
The following main changes might affect your Strapi application and require you to do some manual actions.
For each of them, read the indicated breaking change entry and check if some manual actions are still required after the upgrade tool has run:
- Database migration:
- MySQL v5 is not supported 👉 see breaking change
- Only better-sqlite3 is supported 👉 see breaking change
- Only mysql2 is supported 👉 see breaking change
- Lifecycle hooks are triggered differently 👉 see breaking change
- Configuration:
- Some environment variables are handled by the server configuration 👉 see breaking change
- Custom configuration must meet specific requirements 👉 see breaking change
- Admin panel customization:
- The helper-plugin has been removed 👉 see migration reference
👉 Finally, go over the rest of the breaking changes database for any edge case you might be concerned about.
Step 4: Migrate the API consuming side
Strapi 5 has updated both the REST and GraphQL APIs.
Follow the steps below and leverage retro-compatibility flags and guided migration resources to gradually update your code for Strapi 5.
Migrate REST API calls
- Enable the retro-compatibility flag by setting the
Strapi-Response-Format: v4
header. - Update your queries & mutations only, guided by the dedicated breaking change entry for REST API.
- Validate that your client is running correctly.
- Disable the retro-compatibiliy flag by removing the
Strapi-Response-Format: v4
header and start using the new response format.
Migrate GraphQL API calls
- Enable the retro-compatibility flag by setting
v4CompatibilityMode
totrue
in thegraphl.config
object of the/config/plugins.js|ts
file. - Update your queries and mutations only, guided by the dedicated breaking change entry for GraphQL.
- Validate that your client is running correctly.
- Disable the retro-compatibily flag by setting
v4CompatibilityMode
tofalse
and start using the new response format.