@heroicons/reactでCannot find module エラーが表示されたときの対処法

@heroicons/reactでCannot find module

Reactで@importで@heroicons/react/24/outlineや@heroicons/react/24/solidなどを読み込むと、Cannot find module '@heroicons/react/24/outline' などのエラーが表示されることがあります。

もし、画面上にアイコンが表示されるのにも関わらず、VS Codeなどでこのエラーが表示される場合は、読み込んでいる@heroicons/reactのバージョンが原因です。

対処法は現在の@heroicons/reactをアンインストールして、最新の@heroicons/reactをインストールすれば解決できます。

現在あなたが使用している「@heroicons/react」のバージョンは以下のコマンドで確認できます。

npm list @heroicons/react

@heroicons/reactの最新バージョンはnpmのWebサイトで確認できます。