Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Build Images don't show #10438

Open
D-Learning76 opened this issue Jan 26, 2021 · 5 comments
Open

React Build Images don't show #10438

D-Learning76 opened this issue Jan 26, 2021 · 5 comments

Comments

@D-Learning76
Copy link

So, I have several images on my react App, but, after run the "npm run build" to create an optimization build, the images doesn't appear. Why?

@bineetNaidu
Copy link

Would you add more info about the issue

@Hrishi1999
Copy link

AFAIK, there is a known issue with react-scripts. Try using an older version like 3.4.4

@jurajpiar
Copy link

@Hrishi1999 Could you give us the link to the issue you mention?

Also downgrading isn't really a good solution as CRAv3.4.4 contains some vulnerabilities for which we want to upgrade to v4.

The issue seems to be rooted somewhere in the way CRA4 packages the images, or the way it references them.
The following figure shows resulted DOM with an SVG added using ES6 import:
Screenshot 2021-03-05 at 13 37 07
As you can see the img tag's src prop is set to [object Module] instead of the actual path that you'd expect there.

I suspect this is not an issue if the images are in the local repo (hence it has not been captured in the tests I'm guessing). The reason for this conjecture is that when I import an image from a library (another repo) and point to the file within the src folder it works fine. However if referencing the dist folder (ie the compiled location), it inserts the object into the src prop as seen in the figure.

This wouldn't be that big of a problem if not for the fact that some of the components we use from the given library also contain images and these are broken too, but cannot be "fixed" the same way.

@Hrishi1999
Copy link

@jurajpiar This issue: #9992

@Prashant-Kesharwani
Copy link

So, I have several images on my react App, but, after run the "npm run build" to create an optimization build, the images doesn't appear. Why?

use ".default" after require inside img src, it will fix the issue.
Example:

Earlier => src={require(../../assests/images/${degree.logo_path})}
Later => src={require(../../assests/images/${degree.logo_path}).default}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants