How to import API route in NextJS for getStaticProps?

I think that the Note is related to internal api path

You should not use fetch() to call an API route in your application

I suppose is related to every path that you define in /pages/api/*. Instead of fetch you can simply refactor your code and import data.

So, the code below is correct, don't need any refactoring

export default function Index({ data }) {
  return <div>{data}</div>;
}

export async function getStaticProps() {
  const response = await fetch("http://127.0.0.1:8000/data");
  const data = await response.json();
  return { props: { data } };
}