‘View‘ cannot be used as a JSX component

问题描述

在项目中提示错误如下:
‘View’ cannot be used as a JSX component.
‘View‘ cannot be used as a JSX component_第1张图片

问题原因

原因是:观察 lock 文件可以发现:react 类型声明的文件重复且版本不一致,导致很多子依赖的版本号为 * ,会自动按照最新的版本,与项目中使用的 react 声明文件冲突,如下:
‘View‘ cannot be used as a JSX component_第2张图片

解决方案


// package.json 中添加 resolutions 属性锁定 @types/react 的版本,删除 node_modules 再安装即可
// 这个属性是 yarn 提供的,用于子依赖嵌套版本不一致时,选择版本
"resolutions":{
   "@types/react": "17.0.2"
 },
 

你可能感兴趣的:(taro,react,react.js,javascript,前端)