@types/react 的版本问题 - 升级/锁版本 (我就比较特殊了,因为 @type/react 依赖位置错了)
node_modules 是怎么生成的
安装依赖后,将依赖包下载到 node_modules中存储。
依赖报错
我在项目中运行了npm i,所有的依赖包在项目目录下。但是实际引入的包在根目录的node_modules中,因此会报ts错误:TS2786: *** cannot be used as a JSX component,引入的类型模块是 {}。
为什么项目会使用根目录下的node_modules 而不是项目中的node_modules呢?
这是报错根因:
解决方法
在根目录下 rm -rf node_modules