Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
Next.js GetStaticPaths: ReferenceError: Cannot access 'getAllPostIds' before initialization

I am making a simple next js blog type of application using graphql as a data fetching backend to render text. Using getStaticPaths, I'm running into the following error when I try to fetch data for my page.

ReferenceError: Cannot access 'getAllPostIds' before initialization

Here is my code:

pages/posts/[id].tsx


import { getAllPostIds } from '../../../lib/posts'

const Post = ({ postData }) => {
   ... code.....
}

export const getStaticPaths = async () => {
  const paths = getAllPostIds('aws');

  return {
    paths,
    fallback: false
  }
}

export default Post;

And here is my posts.ts where I use graphql to fetch data.

import { useQuery } from "react-query";
import { GraphQLClient } from "graphql-request";

const GET_POST_IDS = gql`
  query($folder: String!) {
    repository(owner: "assembleinc", name: "documentation") {
      object(expression: $folder) {
        ... on Tree {
          entries {
            name
          }
        }
      }
    }
  }`
;

const graphQLClient = new GraphQLClient('https://api.github.com/graphql', {
  headers: {
    Authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`
  }
});

export const getAllPostIds = (folder: String) => {
  return useQuery(folder, async () => {
    ... fetch data ...
  });
}

Essentially, before I can even get the data through graphql, next js is complaining that getAllPostIds can't be initialized even though I import it at the top. Is there some next.js magic that I am not seeing?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda