Skip to content

汇总:react-router、history 更新引起的相关问题及解决方案 #82

@sorrycc

Description

@sorrycc

持续更新。

Cannot read property 'Consumer' of undefined

react-router@4.4 已被 unpublish,理论上不会再遇到这个问题,遇到的重装 node_modules 后再试。

原因

使用的 react-router 和 react-router-dom 版本不同,通常出现在 ant-design-pro 的用户中,因为 ant-design-pro 手动依赖了一个 react-router-dom@^4.3.1^ 前缀引让 npm/yarn 下载依赖时匹配到 react-router@4.4。

解决

方法一(别这么干)

修改 package.json 中 react-router-dom 的依赖为 4.3.1。能解决问题,但治标不治本,下次 umi 把 react-router 升级到 4.4,就又挂了。

方法二(推荐)

参考 ant-design-pro!3787 修复,删除 react-router-dom 依赖,路由功能全部走 umi。

Module not found: Can't resolve '@babel/runtime/helpers/...'

原因

history 发布了 4.9,而 roadhog 之前版本对于 @babel/runtime 的处理不恰当。

解决

方法一

新建 webpack.config.js,内容如下:

export default function(webpackConfig) {
  delete webpackConfig.resolve.alias['@babel/runtime'];
  return webpackConfig;
}

方法二

roadhog 依赖升级为 ^2.5.0-beta.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions