Skip to main content

Strapi v4 到 Strapi 5 的重大变更

🌐 Strapi v4 to Strapi 5 breaking changes

本页面列出了 Strapi 5 中引入的所有重大更改。重大更改按主题相关类别分组,在下面表格的每一行中,你将找到:

🌐 The present page lists all the breaking changes introduced in Strapi 5. Breaking changes are grouped into topic-related categories, and for each line in the following tables line you will find:

  • 重大更改的简短描述,
  • 以及另外两列,“影响插件”和“由 codemods 处理”,总结了破坏性更改是否也影响插件,以及破坏性更改是否由 升级 CLI 工具 的 codemod 自动处理。

你可以单击下表中任何重大更改的描述以跳转到包含更多详细信息的相应页面。

🌐 You can click on the description of any breaking change in the following tables to jump to the corresponding page with more details.

Tips
  • 要查看可用 codemods 的完整列表,请在终端中运行 npx @strapi/upgrade codemods ls 命令。
  • 要更深入地查看 codemods 执行的代码,请前往 GitHub 仓库中的 list of codemods

数据库

🌐 Database | 描述 | 影响插件 | 由 codemods 处理 ||-------------|-----------------|---------------------|| 内容类型总是有功能列 | 是 | 否 || 不再支持 MySQL v5 | 否 | 否 || 数据库标识符超过 55 个字符将被自动缩短 | 是 | ✅ 是 || SQLite 客户端仅支持 better-sqlite3 | 否 | ✅ 是 || MySQL 客户端仅支持 mysql2 | 否 | ✅ 是 |

依赖

🌐 Dependencies | 描述 | 影响插件 | 由代码修改工具处理 ||-------------|-----------------|---------------------|| CLI 默认的包管理器不再是 yarn | 否 | 否 || Vite 是 Strapi 5 的默认打包工具 | 是 | 否 || Strapi 5 使用 react-router-dom v6 | 是 | ✅ 是 || Strapi 5 使用 koa-body v6 | 是 | 否 || Strapi 5 中移除了 Webpack 别名 | 是 | 否 || Apollo Server v3 升级到 Apollo Server v4 | 是 | 否 |

配置

🌐 Configuration

描述影响的插件由代码转换处理
一些仅适用于 env 的配置选项由服务器配置处理
配置文件名应符合严格要求
服务器日志级别是 http
模型配置路径使用 UID 而不是点表示法👷 部分
webhooks.populateRelations 服务器配置已删除
public 中移除了 defaultIndex 选项
服务器代理配置选项分组在 server.proxy 对象下

Strapi 对象、方法、包和后端自定义

🌐 Strapi objects, methods, packages, and back-end customization | 描述 | 影响插件 | 由代码修改工具处理 ||-------------|-----------------|---------------------|| strapi.fetch 使用原生 fetch() API | 是 | 否 || strapi 工厂导入已更改 | 是 | 👷 部分 || isSupportedImage 方法在 Strapi 5 中已移除 | 是 | 否 || strapi-utils 已被重构 | 是 | ✅ 是 || 核心服务方法使用 Document Service API | 是 | 否 || i18n 现在是 strapi 核心的一部分 | 是 | ✅ 是 |

插件、提供商、管理面板和前端自定义

🌐 Plugins, providers, admin panel and front-end customization

描述影响的插件由代码转换处理
用户与权限 register.allowedFields 默认为 []✅ 是
helper-plugin 已被移除👷 部分
injectContentManagerComponent() 被移除,改用 getPlugin('content-manager').injectComponent()
某些 Mailgun 提供商的旧变量不受支持
lockIcon 属性已被 licenseOnly 取代
ContentManagerAppState redux 已被修改
“EditViewLayout”和“ListViewLayout”已被重构
管理面板 RBAC redux 存储已更新
getWhere 方法用于权限提供者实例已被删除
设计系统已升级

内容 API

🌐 Content API

描述影响的插件由代码转换处理
Strapi 5 为 API 调用提供了新的扁平化响应格式
REST API 输入在控制器中默认被验证
GraphQL API 已更新
实体服务 API 已弃用,已被文档服务 API 取代👷 部分
documentId 应该在 API 调用中替代 id👷 部分
根据文档服务 API 方法,数据库生命周期钩子的触发方式不同
publicationState 参数不受支持,已被 status 取代✅ 是
禁用草稿和发布的内容类型始终将 publishedAt 值设置为日期
按 ID 排序不再能按时间顺序排序✅ 是
在文档服务 API 中没有 findPage() 方法
某些属性和内容类型名称被 Strapi 保留
在创建条目时上传文件不再可能
组件和动态区域应使用详细的填充策略进行填充
不建议使用文档服务 API 更新可重复使用的组件