我收到错误模块未找到:错误:无法解析“@heroicons/react/solid”

dae*_*262 3 reactjs package.json tailwind-css tailwind-ui heroicons

我跑了

npm install @heroicons/react
Run Code Online (Sandbox Code Playgroud)

我的 package.json 看起来像这样:

"dependencies": {
"@headlessui/react": "^1.6.6",
"@heroicons/react": "^2.0.0",
...
Run Code Online (Sandbox Code Playgroud)

但由于某种原因我无法让它工作!

我仍然收到此错误

请帮我一下。我不明白这里有什么问题?

小智 7

在版本中2.0.0根据文档,图标应该从以下位置导入:

  • @heroicons/react/20/solid
  • @heroicons/react/24/outline
  • @heroicons/react/24/solid

例如:

import { AcademicCapIcon } from '@heroicons/react/20/solid';
import { BeakerIcon } from '@heroicons/react/24/outline';
import { PlayIcon } from '@heroicons/react/24/solid';

function Preview() {
  return (
    <div>
      <AcademicCapIcon />
      <BeakerIcon />
      <PlayIcon />
    </div>
  )
}
Run Code Online (Sandbox Code Playgroud)