LoginSignup
0
0

More than 1 year has passed since last update.

Reactのimportでnode_modulesにあるのに見つけることができずVSCodeでエラーになる

Posted at

はじめに

Reactにemotionをいれたところnode_moduleにはあるのにインポートできない問題が起きたのでまとめます
他の方のVSCodeでは問題なく読み込めているようでした

問題

image.png

モジュール '@emotion/cache' が見つかりません。'moduleResolution' オプションを 'node' に設定することか、'paths' オプションにエイリアスを追加することを意図していましたか?ts(2792)

なぜか私の環境ではエラーが出ています。

解決方法

エラー通りにtsconfig.jsonを修正します

tsconfig.jsonをひらくとたしかにエラーになっていました

image.png

bundlernodeに変えます

tsconfig.json
    "moduleResolution": "node",

これでVSCodeのエラーは消えました

シンの解決方法

nodeは非推奨になっているのでbundlerで動かす場合は以下の記事にまとめました

おわりに

おうちで開発していてもよく現れる問題でした。あらためて向き合って理解が進みました

0
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
0
0