我最近将我的 react 仓库移到了/client
. 我在安装时使用 yarn install 安装了 node_modules/client
VS 代码智能感知建议我在导入像和这样的react-hooks时导入 fromhoist-non-react-statics/node_modules/@types/react
而不是 from 。当我使用编译时,这会导致以下错误react
useEffect
useRef
yarn start
未找到module:无法解析 'hoist-non-react-statics/node_modules/@types/react'
我的 package.json 中没有“hoist-non-react-statics”作为依赖项。我的 package.json 依赖项如下:
"dependencies": {
"@auth0/auth0-react": "^1.6.0",
"@hookform/resolvers": "^2.7.1",
"@reduxjs/toolkit": "^1.6.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/qs": "^6.9.7",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.7",
"@types/react-slider": "^1.3.1",
"@types/react-table": "^7.7.2",
"clsx": "^1.1.1",
"final-form": "^4.20.2",
"final-form-calculate": "^1.3.2",
"lodash": "^4.17.21",
"qs": "^6.10.1",
"rc-checkbox": "^2.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-final-form": "^6.5.3",
"react-hook-form": "^7.12.2",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-slider": "^1.3.1",
"react-table": "^7.7.0",
"react-truncate": "^2.4.0",
"typescript": "~4.1.5",
"yup": "^0.32.9"
},
与react相关的@types 似乎是一个问题。我在react-redux
github repo上提交了一个问题。
yarn upgrade @types/react
修复它。为了更好的衡量,所有的包都应该升级yarn upgrade --latest
或只升级所有类型yarn upgrade --latest --pattern "@types"