field-form
field-form copied to clipboard
项目运行报错👉TypeError: reactRouter.matchPath is not a function
复现步骤
我按照README.md的提示运行
npm install
npm start
open http://localhost:8000
当我用浏览器打开http://localhost:8000时,终端报错,并且无法打开页面。
终端错误如下:
App running at:
- Local: http://localhost:8000 (copied to clipboard)
- Network: http://192.168.3.138:8000
(node:70080) UnhandledPromiseRejectionWarning: TypeError: reactRouter.matchPath is not a function
at some (/Users/huang/Hunter/repository/field-form/node_modules/react-router-config/modules/matchRoutes.js:6:9)
at Array.some (<anonymous>)
at matchRoutes (/Users/huang/Hunter/repository/field-form/node_modules/react-router-config/modules/matchRoutes.js:4:10)
at /Users/huang/Hunter/repository/field-form/node_modules/@umijs/preset-built-in/lib/plugins/commands/dev/createRouteMiddleware.js:79:72
期望结果
按照README.md的提示能够正常运行项目。
尝试解决
根据错误提示,发现错误来源于react-router-config调用react-router的matchPath方法。但是react-router-config依赖的react-router版本为 "react-router": ">=5"。但是当前项目依赖的react-router版本"react-router": "^3.0.0"。
所以推断问题的原因是项目依赖react-router的版本过低导致。
在运行npm install [email protected] --save-dev,后项目终于能够正常运行。