我正在尝试将一个简单的 React 组件加载到我的应用程序中(特别是React-rating)。
我运行 Visual Studio,并确保将它添加到我的packages.json
. 并安装所有依赖项(请参阅帖子底部的图像)。
现在,我尝试遵循使用该组件的标准说明。在我的 TSX 文件的顶部,我写道:
var Rating = require('react-rating');
当我使用组件时,我只是使用 <Rating />
现在,这给出了:
TS2604: JSX element type 'Rating' does not have any construct or call signatures.
如果我改为像这样加载模块:
import * as Rating from 'react-rating';
然后我得到:
Could not find a declaration file for module 'react-rating'. '/Likvido.CreditRisk/node_modules/react-rating/lib/react-rating.js' implicitly has an 'any' type.
Try `npm install @types/react-rating` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-rating';`
我想是因为我使用了 Typescript,但在这种情况下,我该如何导入组件?
我的依赖:
潜在的问题是因为我没有正确安装软件包。
我在安装包时停止使用 Visual Studio 中的包控制台,而是确保 NPM 在我的路径中。然后我用运行打开正常控制台cmd
上ctrl+r
(当然,导航到正确的解决方案)。
当您在此处安装软件包时,它们将正确到达 Visual Studio 并安装所有内容,以便它们正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句