简体   繁体   中英

ReactJS: Uncaught ReferenceError: require is not defined

I am trying to read images from folder in reactJS application. I tried with this Solution that is very close to my question on SO but console showing me this error each time.

Here is my code

<img src={require('../images/Mobile/Grab & Go.png')} alt="" />

Console is showing this error

Portfolio.jsx:23 Uncaught ReferenceError: require is not defined

You have to import the image then use it as a value passed to the src prop of img .

import Image from '../images/Mobile/Grab & Go.png';
...
<img src={Image} alt="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM