I want to upload images from files in my React application (I use create-react-app).It didn't show up and the error message appeared in the terminal.
I tried the proposed solution in the following questions but It didn't work out for my app.
Dynamically Add Images React Webpack
The error message is
Module not found: Can't resolve './Image.png' in '/Users/ayumi/my-app/src/components'
Main.js
import React from 'react';
import Image from './Image.png';
export default class Parent extends React.Component {
render() {
return (
<div>
<img src={Image} alt=""} />
</div>
);
}
}
File structure
|-- src
| ` app.js
| ` image.jpg
| `-- components
| `Main.js
Edited Thanks to Chris's comment, it figure it out that just one comma was missing in import area.
import React from 'react';
import Image from '../Image.png';