# Gatsby Image showing 0x0 pixels

**URL:** <https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532>\
**Category:** General\
**Created:** [December 3, 2020, 1:23pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532 "2020-12-03T13:23:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmohamud720](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mmohamud720/32/135521_2.png) [@mmohamud720](https://forum.freecodecamp.org/u/mmohamud720)\
**Post date:** [December 3, 2020, 1:23pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/1 "2020-12-03T13:23:45Z")

</div>

HI i have been learning gatsby and im trying to use gatsby image but my images are not showing however you ca see it in the console wit 0 x 0 pixels. below I will put in the code for my config file and the file with the query along with a screenshot of the console  
gatsby-config.js

```auto
module.exports = {
  siteMetadata: {
    title: `Mo-Travel`,
    description: `My travel website showcasing the best destinations and deals`,
    author: `Mohamed Mohamud`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-styled-components`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/assets/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `video`,
        path: `${__dirname}/src/assets/videos`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    `gatsby-transformer-json`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `./src/data/`,
      },
    },
  ],
};

```

query file

```auto
import React from 'react';
import styled from 'styled-components';
import { graphql, useStaticQuery } from 'gatsby';
import Img from 'gatsby-image';
import { Button } from './Button';

const Trips = () => {
  const data = useStaticQuery(graphql`
    query MyQuery {
      allTripsJson {
        edges {
          node {
            alt
            button
            name
            img {
              childImageSharp {
                fluid(maxHeight: 600, maxWidth: 600) {
                  ...GatsbyImageSharpFluid
                }
              }
            }
          }
        }
      }
    }
  `);

  function getTrips(data) {
    const tripsArray = [];
    data.allTripsJson.edges.forEach((item, index) => {
      tripsArray.push(
        <ProductCard key={index}>
          <Img
            src={item.node.img.childImageSharp.fluid.src}
            alt={item.node.alt}
            fluid={item.node.img.childImageSharp.fluid}
            
          />
          <ProductInfo>
            <TextWrap>
              <ImLoaction />
              <ProductTitle>{item.node.name}</ProductTitle>
            </TextWrap>
            <Button to='/trips'>{item.node.button}</Button>
          </ProductInfo>
        </ProductCard>
      );
    });
    return tripsArray;
  }

  return (
    <ProductsContainer>
      <ProductsHeading>Heading</ProductsHeading>
      <ProductWrapper>{getTrips(data)}</ProductWrapper>
    </ProductsContainer>
  );
};

export default Trips;

const ProductsContainer = styled.div`
  min-height: 100vh;
  padding: 5rem calc((100vw -1300px) / 2);
  background: violet;
  color: #fff;
`;

const ProductsHeading = styled.div`
  font-size: clamp(1.2rem, 5vw, 3rem);
  text-align: center;
  margin-bottom: 5rem;
  color: #000;
`;

const ProductWrapper = styled.div``;

const ProductCard = styled.div``;

const ProductInfo = styled.div``;

const TextWrap = styled.div``;

const ImLoaction = styled.div``;

const ProductTitle = styled.div``;

```

 ![Screen Shot 2020-12-03 at 12.53.54](https://global.discourse-cdn.com/freecodecamp/original/3X/6/e/6eae2d50e023ea5840afa472bb189ec7a848ace3.png)

---

<div class="post-metadata">

**Author:** ![nibble](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nibble/32/123681_2.png) [@nibble](https://forum.freecodecamp.org/u/nibble)\
**Post date:** [December 3, 2020, 3:34pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/2 "2020-12-03T15:34:08Z")

</div>

Hi @mmohamud720. I have never used gatsby before but I am seeing `opacity: 0` and `position: absolute` somewhere in the inline CSS. Are you sure they are not the cause of your troubles?

---

<div class="post-metadata">

**Author:** ![mmohamud720](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mmohamud720/32/135521_2.png) [@mmohamud720](https://forum.freecodecamp.org/u/mmohamud720)\
**Post date:** [December 3, 2020, 3:51pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/3 "2020-12-03T15:51:02Z")

</div>

all of the styling is automatic from gatsby-image so I can’t change it. Im using it because it make images auto responsive and it’s a decent intro to graphql

---

<div class="post-metadata">

**Author:** ![ptricky](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ptricky/32/197060_2.png) [@ptricky](https://forum.freecodecamp.org/u/ptricky)\
**Post date:** [January 2, 2021, 10:58pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/4 "2021-01-02T22:58:37Z")

</div>

I had the same issue which is what brought me here.  
The reason this seems to happen is due to the **container** not having a size. Try setting a size on parent and it should show up.

---

<div class="post-metadata">

**Author:** ![mmohamud720](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mmohamud720/32/135521_2.png) [@mmohamud720](https://forum.freecodecamp.org/u/mmohamud720)\
**Post date:** [January 2, 2021, 11:15pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/5 "2021-01-02T23:15:22Z")

</div>

Wow that actually worked, I gave up on the project haha. Thanks to you I’ll go back to it

---

<div class="post-metadata">

**Author:** ![ptricky](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ptricky/32/197060_2.png) [@ptricky](https://forum.freecodecamp.org/u/ptricky)\
**Post date:** [January 3, 2021, 6:22am UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/6 "2021-01-03T06:22:28Z")

</div>

Awesome!! Glad it helped! I’ve found Gatsby images the hardest part to understand in Gatsby, but it’s really cool once it’s working!

---

<div class="post-metadata">

**Author:** ![kayub0071](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kayub0071/32/198523_2.png) [@kayub0071](https://forum.freecodecamp.org/u/kayub0071)\
**Post date:** [January 10, 2021, 9:11am UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/7 "2021-01-10T09:11:42Z")

</div>

**TypeError: Cannot read property ‘childImageSharp’ of null**

Trips.js

```auto
import React from 'react'
import styled from 'styled-components'
import {useStaticQuery, graphql} from 'gatsby'
import Img from 'gatsby-image'

const Trips = () => {
  const data = useStaticQuery(graphql`
  query TripsQuery {
    allTripsJson {
      edges {
        node {
          alt
          button
          name
          img {
            childImageSharp {
              fluid {
                ...GatsbyImageSharpFluid
              }
            }
          }
        }
      }
    }
  }
  `)

  function getTrips(data){
    const tripsArray = []
    data.allTripsJson.edges.forEach((item, index) => {
      tripsArray.push(
        <div key={index}>
          <Img src={item.node.img.childImageSharp.fluid.src}
          fluid={item.node.img.childImageSharp} />
        </div>
      )
    })
    return tripsArray

  }

  return (
    <div>
      <ProductsContainer>
        <ProductHeading>Heading</ProductHeading>
        <ProductWrapper>{getTrips(data)}</ProductWrapper>
      </ProductsContainer>
    </div>
  )
}

export default Trips

const ProductsContainer = styled.div`
  min-height: 100vh;
  width: 100vw;
  width: 100%;
  padding: 5rem calc((100vw - 1300px) / 2);
  background: red;
  color:#fff;

`
const ProductHeading = styled.div`
  font-size: clamp(1.2rem, 5vw, 3rem);
  text-align: center;
  margin-bottom: 5rem;
  color:#000;
`
const ProductWrapper = styled.div`

`

```

config.js

```auto
module.exports = {
  siteMetadata: {
    title: `Explore Naija`,
    description: `Travel website showcasing the best travel destination and deals online.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-styled-components`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/assets/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `videos`,
        path: `${__dirname}/src/assets/videos`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    `gatsby-transformer-json`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `./src/data/`,
      },
    },

  ],
}

```

trps.json

```auto
[
  {
    "img": "../assets/images/landing-page.jpg",
    "alt": "tin tan buddah",
    "name": "tian tan budah",
    "button": "view destinantion"
  },
  {
    "img": "../assets/images/obub-cattle-ranch-top.jpg",
    "alt": "tin tan buddah",
    "name": "tian tan budah",
    "button": "view destinantion"
  },
  {
    "img": "../assets/images/obudu-hiltop-road.jpg",
    "alt": "tin tan buddah",
    "name": "tian tan budah",
    "button": "view destinantion"
  },
  {
    "img": "../assets/images/yankari-game-reserve-bauch2.jpg",
    "alt": "tin tan buddah",
    "name": "tian tan budah",
    "button": "view destinantion"
  }
]

```

@ptricky @mmohamud720 pls help me check this out i do not want to abandon this project

---

<div class="post-metadata">

**Author:** ![ptricky](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ptricky/32/197060_2.png) [@ptricky](https://forum.freecodecamp.org/u/ptricky)\
**Post date:** [January 10, 2021, 10:58pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/8 "2021-01-10T22:58:35Z")

</div>

Hey! Happy to (try to) help.

I think the problem is here:  
`<ProductWrapper>{getTrips(data)}</ProductWrapper>`

First, getTrips() returns an array. Second, that won’t run until it’s called so the data won’t necessarily be ready when it attempts to draw the first time.

You might be better off doing something like this (and getting rid of the getTrips() function.

```auto
<div>
      <ProductsContainer>
        <ProductHeading>Heading</ProductHeading>
        {data.map( elem => (
             <ProductWrapper key={elem.id}>
                      <Img src={item.node.img.childImageSharp.fluid.src}
                                   fluid={item.node.img.childImageSharp} />
           </ProductWrapper> 
         )}        
      </ProductsContainer>
    </div>

```

I hope that helps. If I’m way off, maybe you have a working instance running that I can look at.

---

<div class="post-metadata">

**Author:** ![kayub0071](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kayub0071/32/198523_2.png) [@kayub0071](https://forum.freecodecamp.org/u/kayub0071)\
**Post date:** [January 11, 2021, 2:59pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/9 "2021-01-11T14:59:24Z")

</div>

@ptricky thanks for your quick response after a lot of stackoverflow and a lot of code forum i later resolve it by renaming my image thanks

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:36pm UTC](https://forum.freecodecamp.org/t/gatsby-image-showing-0x0-pixels/433532/10 "2021-06-01T18:36:36Z")

</div>

Closed on June 1, 2021, 6:36pm UTC


