Strapi factories import have been updated
In Strapi 5, strapi factories import have been updated.
This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
🔌 Is this breaking change affecting plugins? | Yes |
---|
🤖 Is this breaking change automatically handled by a codemod? | No |
---|
Breaking change description
In Strapi v4
Imports are done as follows:
using the application init function:
import strapi from '@strapi/strapi';
// or
const strapi = require('@strapi/strapi');
strapi();using the factories:
import strapiDefault from '@strapi/strapi';
// or
import { factories } from '@strapi/strapi';
// or
const { factories } = require('@strapi/strapi');
// or
const { createCoreService } = require('@strapi/strapi').factories;
// or
const strapi = require('@strapi/strapi');
strapiDefault.factories.createCoreService(); // this is not possible anymore in v5
strapi.factories.createCoreService();
factories.createCoreService();
createCoreService();
In Strapi 5
Imports are done as follows:
using the application init function
import { createStrapi } from '@strapi/strapi';
const { createStrapi } = require('@strapi/strapi');
const strapi = require('@strapi/strapi');
strapi.createStrapi();using the factories:
// Using the factories
import { factories } from '@strapi/strapi';
// or
const { factories } = require('@strapi/strapi');
// or
const { createCoreService } = require('@strapi/strapi').factories;
// or
const strapi = require('@strapi/strapi');
strapi.factories.createCoreService();
factories.createCoreService();
createCoreService();
// The recommended way is
const { factories } = require('@strapi/strapi');
import { factories } from '@strapi/strapi';
factories.createCoreService();
Migration
- The upgrade tool converts the application instantiation with a codemod.
- The factories pattern that were removed will not be converted automatically.