我正在尝试将 antd
库添加到从 Visual Studio 2017 (15.2.2) 生成的 React 项目中。
我从项目模板“ASP.NET Core Web Application”开始,然后在下面的窗口中选择了“React.js”。
此时一切正常。
如果我在 package.json
("antd": "3.1.0") 中添加 antd
并在一些 tsx
中添加导入> 文件,例如像这样的 home.tsx
:
import { Row } from 'antd';
我得到 3 个错误:
ERROR in [at-loader] ./node_modules/antd/lib/badge/ScrollNumber.d.ts:28:56 TS2694: Namespace 'React' has no exported member 'DetailedReactHTMLElement'.
ERROR in [at-loader] ./node_modules/antd/lib/badge/ScrollNumber.d.ts:38:52 TS2694: Namespace 'React' has no exported member 'DetailedReactHTMLElement'.
ERROR in [at-loader] ./node_modules/antd/lib/input/TextArea.d.ts:15:47 TS2694: Namespace 'React' has no exported member 'TextareaHTMLAttributes'.
如何修复这些错误?
我已尝试更新所有软件包,但仍然出现相同的错误... 我有一些其他项目同时使用 React 和 antd,它们不是基于 Visual Studio 2017 提供的 React.js 模板,我没有任何错误。
感谢您的帮助!
最佳答案
解决这个问题最简单的方法是升级你的“typescript”包和所有你的 React 相关包(包括@types/react-*)除了“react-hot-loader”(只升级到最新的 ^3)到他们最新的主要版本。
如果仍有问题,请删除 node_modules、yarn.lock、npm-shrinkwrap.json 和 wwwroot/dist,然后重试。
关于reactjs - react + antd TS2694 : Namespace 'React' has no exported member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48127161/