Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
Query returning error "Cannot read properties of undefined (reading 'nodes')"

I am trying to write a page query to return a line of text and an image in a GatsbyJS project. I am using Gatsby Image plugin along with 'gatsby-transformer-sharp' and 'gatsby-plugin-sharp' and I keep getting an error that the nodes returned from the query are undefined.

My query looks like this:

query ProjectsPage {
  allMarkdownRemark {
    nodes {
      frontmatter {
        featuredImg {
          childImageSharp {
            fluid{
              ...GatsbyImageSharpFluid
            }
          }
        }
        title
      }
    }
  }
}

The line of code giving me the error:

const projects = data.projects.nodes

And my gatsby-config.js file looks like this:

 module.exports = {
   /* Your site config here */
   plugins: [
     'gatsby-transformer-remark',
     'gatsby-transformer-sharp',
     'gatsby-plugin-sharp',
     {
       resolve: `gatsby-source-filesystem`,
       options: {
         name: `projects`,
         path: `${__dirname}/src/projects/`,
        },
      },
      {
        resolve: `gatsby-source-filesystem`,
        options: {
          name: `images`,
          path: `${__dirname}/src/images/`,
         },
       },
   ],
   siteMetadata: {
     title: 'example',
     description: 'web dev portfolio',
     copyright: 'example text'
   },
 }

I would really appreciate any help on this!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The correct way to get the nodes from your query is:

const projects = data.allMarkdownRemark.nodes

If you want to filter your results by directory and only get nodes from within projects, you can follow one of the answers here and use something like:

query ProjectsPage {
 allMarkdownRemark(filter: {fileAbsolutePath: {regex: "/(/projects/)/"}}) {
    nodes {
      frontmatter {
        featuredImg {
          childImageSharp {
            fluid {
              ...GatsbyImageSharpFluid
            }
          }
        }
        title
      }
    }
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda