删除 Ant Design Pro 中的【国际化】模块报错:Environment key “es2022“ is unknown

问题描述

使用 npm run i18n-remove 运行 “i18n-remove”: “pro i18n-remove --locale=zh-CN --write” 删除【国际化】模块时出现如下报错:
在这里插入图片描述

问题分析

报错的大致意思是,在 \node_modules\@umijs\lint\dist\config\eslint\index.js 文件中找不到 es2022 这个环境配置的关键字。

解决方案

该配置和我们删除【国际化】模块关系不大,所以我采取的方式是进入 \node_modules@umijs\lint
\dist\config\eslint\index.js 文件中,注释掉 es2022 属性,再次运行 npm run i18n-remove 完美解决。
在这里插入图片描述
再次运行npm run i18n-remove ,发现又报如下错误:

<color='red> Error: Failed to load plugin ‘unicorn’ declared in ‘BaseConfig’: Cannot find module ‘eslint-plugin-unicorn’

查官网发现,给出了相应的解决方案 ,缺依赖包,需要加上以下依赖包:

npm i @typescript-eslint/eslint-plugin
npm i eslint-plugin-eslint-comments
npm i eslint-plugin-jest
npm i eslint-plugin-unicorn

再次运行npm run i18n-remove ,发现【国际化】模块和其他模块的依赖关系解除成功。
运行 npm run start 查看前端项目是否可以正常启动,发现左侧菜单栏消失了,在官网搜索,找到了 解决方案 ,做如下修改:
将 config 模块的 route.js 配置文件的每一条路由都加上对应的 name 属性,如下:

export default [
  { name: '登录', path: '/user', layout: false, routes: [{ path: '/user/login', component: './User/Login' }] },
  { name: '欢迎页面', path: '/welcome', icon: 'smile', component: './Welcome' },
  {
    path: '/admin',
    icon: 'crown',
    access: 'canAdmin',
    name: '管理员页面',
    routes: [
      { path: '/admin', redirect: '/admin/sub-page' },
      { path: '/admin/sub-page', component: './Admin' },
    ],
  },
  { icon: 'table', path: '/list', component: './TableList', name: '表格页' },
  { path: '/', redirect: '/welcome' },
  { path: '*', layout: false, component: './404' },
];

再次刷新前端项目,结果就显示出来了,完美解决。

注意事项

运行命令 npm run i18n-remove 删除后,需要手动删除 src/locales 包。

官网可解决的问题

如下的报错,可以进 Ant Design Pro 官网提供的 GitHub 官网连接找到答案
在这里插入图片描述
上面的报错,运行如下命令即可解决:

npm i --save-dev prettier eslint-config-prettier eslint-plugin-prettier

注意:这个 BUG 应该会出现在上一个 BUG 之前,新的 nodejs 版本(>= v16.13.0)在删除国际化模块时,会出现这个问题.

  • 42
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值