Skip to content

React Build Images don't show #10438

Open

Description

@D-Learning76

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?

Activity

  1. bineetNaidu commented on Jan 27, 2021

    @bineetNaidu

    Would you add more info about the issue

  2. Hrishi1999 commented on Feb 6, 2021

    @Hrishi1999

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

  3. jurajpiar commented on Mar 5, 2021

    @jurajpiar

    @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.

  4. Hrishi1999 commented on Mar 5, 2021

    @Hrishi1999

    @jurajpiar This issue: #9992

  5. Prashant-Kesharwani commented on Mar 29, 2021

    @Prashant-Kesharwani

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions