【发布时间】:2021-11-01 09:44:41
【问题描述】:
我最近将我的 react 存储库移到了 /client 下的单个单声道存储库中。我在 /client 时使用 yarn install 安装了 node_modules
VS code intellisense 建议我在导入 useEffect 和 useRef 之类的反应钩子时从 hoist-non-react-statics/node_modules/@types/react 而不是从 react 导入。当我使用 yarn start 编译时,这会导致以下错误
找不到模块:无法解析 'hoist-non-react-statics/node_modules/@types/react' in
我的 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"
},
这似乎是与反应相关的@types 的问题。我在react-redux github repo 上提交了一个问题。
yarn upgrade @types/react 修复它。为了更好的衡量,所有的包都应该升级为yarn upgrade --latest,或者只是所有的类型都升级为yarn upgrade --latest --pattern "@types"
【问题讨论】:
-
我突然遇到了同样的情况,而且由于其他人也在这个线程中这样做,我怀疑 VSCode 中的错误。对我来说,它发生在 react-router 和其他几个库中。
-
经过更多测试,我发现这是最新的打字稿版本(4.4.2+)中的一个错误,我将创建一个解决方案的答案
标签: reactjs visual-studio-code node-modules intellisense