I am building a simple react portfolio app. I have the info for my portfolio items stored in a JSON file.
When I attempt to use the image code for the portfolio item, it does not return the correct path. Instead it returns "[object Module]" where the path should be.
Code:
import React, { Component } from 'react';
export default class WorkItemFocus extends Component {
...
render() {
if (this.props.activeItemId === '') {
return (
<div className="text-center">
<p>Please select an item below to view more details.</p>
</div>
)
} else {
const { name, description, tags, img_code } = this.props.activeItem;
return (
...
<img
src={require(`../assets/img/${img_code}`)}
alt={name}
/>
...
)
}
}
}
I have looked online and mostly it says I am not using webpack. My package-lock.json file says it is installed under react-scripts.
I did this just two months ago for someone else and did not encounter this problem. Is there something I am missing?