Repository: umijs/dumi

Issue #1895: bug: 编写react组件demo,用到了react-router@5，code代码报错
Created: 2023-09-14T08:22:45Z
编写react组件demo,用到了react-router@5，code代码报错
TypeError: (0 , react_router_dom__WEBPACK_IMPORTED_MODULE_12__.withRouter) is not a function

Versions

dumi:2.2.7
node:16.14.0
npm:8.3.1
OS:windows10
Browser:chrome

Steps to reproduce
react-router-dom@5：组件使用了 import { withRouter } from 'react-router-dom';
demo 使用这个组件
运行dumi dev 报错
What is Expected?
react旧版都支持，路由5旧版希望也支持
What is actually happening?

Duplicate issue #2024: bug: useRouteMatch was not found in 'react-router'
Created: 2024-02-04T17:51:53Z
Version
2.2.17
OS Version
macOs 14.2
Node.js Version
16.20.0
Browser Version
chrome latest
Link to minimal reproduction
稍后提供
Steps to reproduce
dumi dev
What is expected?
dumi dev 还能继续访问。 但是 dumi build 就直接报错了。
从提示上看，貌似是哪里用了 react-router6。 我组件库项目中是用 react-router5。
然后导致找不到。
What is actually happening?
error - ./packages/react/src/hook/use_memo_route_match.ts:6:14-27
export 'useRouteMatch' (imported as 'useRouteMatch') was not found in 'react-router' (possible exports: MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes)
error - Error: ERROR in ./packages/react/src/hook/use_memo_route_match.ts 6:14-27
export 'useRouteMatch' (imported as 'useRouteMatch') was not found in 'react-router' (possible exports: MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes)
@ ./packages/react/src/index.ts 4:0-60 19:0-22:77
@ ./node_modules/.cache/mfsu/mf-va_@ones-wb_react.js 1:0-96 1:0-96
@ container entry ./@ones-wb/react[0]
MFSU compiled with 1 error
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+mfsu@4.1.1/node_modules/@umijs/mfsu/dist/depBuilder/depBuilder.js:52:20
at finalCallback (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:62945:32)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63009:17
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:77363:3
at Hook.eval [as callAsync] (eval at create (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:7682), :22:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:4851)
at Cache.storeBuildDependencies (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:52350:37)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63005:19
at Hook.eval [as callAsync] (eval at create (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:7682), :47:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:4851)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63002:23
at Compiler.emitRecords (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63423:5)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:62994:11
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63389:14
at Hook.eval [as callAsync] (eval at create (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:7682), :10:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:4851)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63386:27
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:39750:7
at done (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:40454:9)
at Hook.eval [as callAsync] (eval at create (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:7682), :6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-utils@4.1.1/node_modules/@umijs/bundler-utils/compiled/tapable/index.js:1:4851)
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:63240:33
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+bundler-webpack@4.1.1_typescript@5.3.3_webpack@5.90.1/node_modules/@umijs/bundler-webpack/compiled/webpack/index.js:35193:16
at /Users/liyatang/ones/ones-web-business/node_modules/.pnpm/@umijs+utils@4.1.1/node_modules/@umijs/utils/compiled/fs-extra/index.js:1:23246
at FSReqCallback.oncomplete (node:fs:192:23)
Any additional comments? (optional)
No response

Closing comment (2024-02-27T08:37:13Z): Duplicate of #1895 (comment)