Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

368
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!