无法在React中使用NPM软件包
我想使用 tagcloud 在我的React App中,但我无法使其工作。 我没有在控制台中收到任何错误消息,只是没有出现。 我在普通的HTML和JS中使用了相同的代码,
由于此错误,我必须以另一种方式导入该软件包:
Could not find a declaration file for module 'TagCloud'. 'D:/Javascript/portfolio/node_modules/TagCloud/dist/TagCloud.js' implicitly has an 'any' type.
这是我的React组件
import React from 'react';
import './about.scss';
function About() {
const TagCloud = require('TagCloud');
const Tags = [
'JavaScript',
'CSS',
'HTML',
'Vscode',
'XD',
'React',
'Python',
'Linux',
'git',
'Flutter',
'Dart',
'Firebase',
'SASS',
'JSON',
'Figma',
];
TagCloud('.content', Tags, {
radius: 250,
maxSpeed: 'fast',
initSpeed: 'fast',
direction: 135,
keep: true,
});
return (
<div className="About" id="About">
<div className="left">
<div className="heading">
<h1>ABOUT</h1>
</div>
</div>
<div className="right">
<span className=".content">
</span>
</div>
</div>
);
}
export default About;
I want to use TagCloud in my React app but I am not able to get it to work.
I don't get any error message in the console, it just doesn't appear.
I used the same code in plain HTML and JS and it worked there
I had to import the package in another way due to this error:
Could not find a declaration file for module 'TagCloud'. 'D:/Javascript/portfolio/node_modules/TagCloud/dist/TagCloud.js' implicitly has an 'any' type.
This is my React component
import React from 'react';
import './about.scss';
function About() {
const TagCloud = require('TagCloud');
const Tags = [
'JavaScript',
'CSS',
'HTML',
'Vscode',
'XD',
'React',
'Python',
'Linux',
'git',
'Flutter',
'Dart',
'Firebase',
'SASS',
'JSON',
'Figma',
];
TagCloud('.content', Tags, {
radius: 250,
maxSpeed: 'fast',
initSpeed: 'fast',
direction: 135,
keep: true,
});
return (
<div className="About" id="About">
<div className="left">
<div className="heading">
<h1>ABOUT</h1>
</div>
</div>
<div className="right">
<span className=".content">
</span>
</div>
</div>
);
}
export default About;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果
Result