为什么要从";hoist-non-react-statics/node_modules/@types/react";导入VS代码 [英] Why is VS Code importing from "hoist-non-react-statics/node_modules/@types/react"
本文介绍了为什么要从";hoist-non-react-statics/node_modules/@types/react";导入VS代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近在/client
下将我的反应回购移到了一个单声道回购中。我在/client
useEffect
和useRef
这样的Reaction挂钩时从hoist-non-react-statics/node_modules/@types/react
导入,而不是从react
导入。当我使用yarn start
进行编译时,这会导致以下错误
找不到模块:无法解析
中的‘hoist-non-react-statics/node_modules/@types/react’
我的Package.json中没有‘hoist-non-action-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"
},
这似乎是与Reaction相关的@类型的问题。我在react-redux
GitHub回购上提交了一个问题。
yarn upgrade @types/react
修复它。另外,所有包可能都应该使用yarn upgrade --latest
升级,或者只使用yarn upgrade --latest --pattern "@types"
https://github.com/reduxjs/react-redux/issues/1806
推荐答案
降级/升级VSCode和打印脚本版本后,我发现最新的打印脚本版本(用4.4.2测试,但整个4.4.x分支都可能存在)会出现这个问题。该问题似乎不存在于4.3.5中。您可以执行以下操作:
- 将VSCode更新为最新版本
- 确保您安装了TS 4.3.5或更早版本(全局安装或在工作区项目中安装)
- 打开扩展名为
.ts
的任何文件 - 使用状态栏中的下拉列表选择打字版本。您希望选择工作区版本或您的全局版本,而不是VSCode的预安装版本。
这篇关于为什么要从";hoist-non-react-statics/node_modules/@types/react";导入VS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文