完整的错误是:
Unhandled Promise Rejection: TypeError: useSyncExternalStore is not a function. (In 'useSyncExternalStore(subscribe, getSelection, getServerSelection)', 'useSyncExternalStore' is undefined)
仅当我添加以下代码时才会发生这种情况:
const mfeConfig = useSelector((state: any) => state.ccmConfig);
useEffect(() => {
console.log("calculator", mfeConfig)
},[mfeConfig]);
自从我添加了 redux-saga 并让它工作以来,我认为我的react-redux包也很好,但是这个问题只在我使用Selector时发生,所以也许我认为这是我的react依赖项的问题,但我不这样做不知道问题是什么:
npm uninstall react-redux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @types/[email protected]
npm ERR! node_modules/@types/react
npm ERR! peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/[email protected]
npm ERR! node_modules/@mui/base
npm ERR! @mui/base@"5.0.0-beta.37" from @mui/[email protected]
npm ERR! node_modules/@mui/material
npm ERR! peer @mui/material@"^5.0.0" from @mui/[email protected]
npm ERR! node_modules/@mui/icons-material
npm ERR! @mui/icons-material@"^5.8.0" from the root project
npm ERR! 1 more (the root project)
npm ERR! peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/[email protected]
npm ERR! node_modules/@mui/icons-material
npm ERR! @mui/icons-material@"^5.8.0" from the root project
npm ERR! 14 more (@mui/material, @mui/private-theming, @mui/system, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@"^18.2.25" from [email protected]
npm ERR! node_modules/react-redux
npm ERR! peerOptional react-redux@"^7.2.1 || ^8.1.3 || ^9.0.0" from @reduxjs/[email protected]
npm ERR! node_modules/@reduxjs/toolkit
npm ERR! @reduxjs/toolkit@"^2.2.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @types/[email protected]
npm ERR! node_modules/@types/react
npm ERR! peerOptional @types/react@"^18.2.25" from [email protected]
npm ERR! node_modules/react-redux
npm ERR! peerOptional react-redux@"^7.2.1 || ^8.1.3 || ^9.0.0" from @reduxjs/[email protected]
npm ERR! node_modules/@reduxjs/toolkit
npm ERR! @reduxjs/toolkit@"^2.2.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
我正在使用以下软件包:
"react": "^17.0.2",
"react-chartjs-2": "^5.2.0",
"react-csv": "^2.2.2",
"react-dom": "^17.0.2",
"react-redux": "^9.1.2",
"react-router-dom": "^6.3.0",
"react-select": "^5.7.3",
"react-test-renderer": "^17.0.2",
"recharts": "^2.8.0",
"redux": "^5.0.1",
"redux-logger": "^3.0.6",
"redux-saga": "^1.3.0",
"@types/react": "^17.0.2",
"@types/react-csv": "^1.1.10",
"@types/react-dom": "^17.0.2",
"@types/redux-logger": "^3.0.13",
问题实际上出在 React-Redux 的第 9 版中,删除了软件包并使用 8.1.3 修复了问题以及需要 Legacy-peer-deps npm 标志。