You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Strapi插件本地化配置启动报错求助:Cannot read property 'routes'

Strapi添加本地化后启动报错:Cannot read property 'routes' of undefined

给Strapi内容模型添加i18n本地化配置后,服务器无法启动,报错「Cannot read property 'routes' of undefined」。已安装i18n插件,但问题仍未解决。

错误日志

debug: ⛔️ Server wasn't able to start properly.
[2022-09-22 11:30:06.580] error: Cannot read property 'routes' of undefined
TypeError: Cannot read property 'routes' of undefined
    at Object.addCreateLocalizationAction 

内容模型代码

module.exports = {
  kind: "collectionType",
  collectionName: "tests",
  info: {
    singularName: "test",
    pluralName: "tests",
    displayName: "test"
  },
  options: {
    "draftAndPublish": true
  },
  pluginOptions: {
    i18n: {
      localized :true
    }
  },
  attributes: {
    name: {
      pluginOptions: {
        i18n: {
          localized: true
        }
      },
      type: "string",
      required: true
    }
  }
}

解决方案

  • 版本兼容性检查:该报错多出现于Strapi v4早期版本与i18n插件的适配问题,建议将Strapi升级到v4.3及以上版本,同时搭配i18n插件v4.1及以上版本。
  • 重置缓存并重建:删除项目根目录下的.cache和build文件夹,执行npm run build后再启动服务。
  • 确认i18n插件启用配置:在config/plugins.js中确保i18n插件已正确配置启用,示例配置如下:
module.exports = ({ env }) => ({
  i18n: {
    config: {
      locales: ['en', 'zh-CN'],
      defaultLocale: 'en',
      displayDefaultLocale: true,
    },
  },
});
  • 简化模型配置测试:暂时移除属性级别的pluginOptions.i18n配置,只保留模型根级的本地化设置,测试是否能正常启动,逐步排查配置问题。

内容的提问来源于stack exchange,提问作者meh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 12:35:30