LoginSignup
0
0

More than 1 year has passed since last update.

[React]Module not found: Can't resolve '../images/**' 画像が読み込めないエラー対処

Last updated at Posted at 2021-09-08

問題

Reactで画像を表示させるために、localに画像ファイルを保存し、importすると以下のエラーがでた。

Module not found: Can't resolve '../images/**' in 'C:\Users....'

正しいパスでインポートしているはずなのになぜ、、、

解決策

下記に書き直すだけでなおった。

qiita.rb
import Image from '../images/**.png' //pngをつける

export const Result = () => {
    return (
        //....
            <img src={Image}  />
    );
};

予測ででたパスを指定したので、絶対間違ってすこし詰まった😱

ちなみに

Reactで画像を表示するには

1.上記のようにimportする
2.srcにパス名を指定する
の2つがあるようだがどちらが良いのか。。。

1は、importしているため画像に問題がった際にエラーになりすぐに気づける。特に問題がなければ1の方がよさそう!

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