1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React】styled-componentsを使用した際のエラー、`Invalid Hook Call ` `Cannot read properties of null (reading 'useContext')`エラー

Posted at

初めに

reactでstyled-componentsを使用した際に直面したエラー

大きく2つのエラーが出ていました

Invalid Hook Call

Cannot read properties of null (reading 'useContext') TypeError: Cannot read properties of null (reading 'useContext')

現象

npmでインストールした後、styled-componentsを使用して画面表示をしようとしたら表示されない。

原因

npm iを叩くディレクトリが間違っていた。

いつもインストールしていたとことの1つ上の階層で叩いてしまい、PCのグローバルのnode_modulesにもstyled-componentsが入ってしまいそれが悪さしているようでした。

解決法

まずnpmのrootはどこになっているかを確認する。

npm root

/Users/yoshi/node_modules

自分のマックでは上記になっていた。

そこをみにいくと

スクリーンショット 2025-09-03 21.35.13.png

しっかり入っていた。

こちらを削除して、もう一回npm run devして解決

まとめ

思わぬところに落とし穴がありました。

叩くコマンド、場所とかは注意していきたいですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?