Github + NextJS error


I’m following this tutorial:

The authorization process went fine before the step where you configure index.tsx to pull from Github. Specifically, this code raises an uncaught error:

return getGithubPreviewProps({
  fileRelativePath: "content/home.json",
  parse: parseJson,

Here is my repo with the code:

Figured it out. Github names their default branch main on new repositories, not master. Still doesn’t fix it though. Something in the code must be hard coded to look for master, since if I change the .env variable to main I still get the same error. If I instead make a branch named master, it works as expected.

Here’s the issue. The example doesn’t use the BASE_BRANCH env variable to set the base branch. Need to add this to the example:

const github = new GithubClient({
  proxy: "/api/proxy-github",
  authCallbackRoute: "/api/create-github-access-token",
  clientId: process.env.GITHUB_CLIENT_ID,
  baseRepoFullName: process.env.REPO_FULL_NAME,
  baseBranch: process.env.BASE_BRANCH,  // Needs this for new repos, since the default is now main

Good call, GitHub recently changed this, feel free to open an issue. Thanks.

Thank you for pointing this out! I made a PR to update the example in the guide.

1 Like