diff --git a/packages/create-next-app/helpers/examples.ts b/packages/create-next-app/helpers/examples.ts index 62b3d3cd6afb..7de868374b3c 100644 --- a/packages/create-next-app/helpers/examples.ts +++ b/packages/create-next-app/helpers/examples.ts @@ -25,9 +25,15 @@ export async function getRepoInfo( const [, username, name, t, _branch, ...file] = url.pathname.split('/') const filePath = examplePath ? examplePath.replace(/^\//, '') : file.join('/') - // Support repos whose entire purpose is to be a NextJS example, e.g. - // https://github.com/:username/:my-cool-nextjs-example-repo-name. - if (t === undefined) { + if ( + // Support repos whose entire purpose is to be a NextJS example, e.g. + // https://github.com/:username/:my-cool-nextjs-example-repo-name. + t === undefined || + // Support GitHub URL that ends with a trailing slash, e.g. + // https://github.com/:username/:my-cool-nextjs-example-repo-name/ + // In this case the "_branch" does not exist while the "t" is an empty string + (t === '' && _branch === undefined) + ) { const infoResponse = await got( `https://api.github.com/repos/${username}/${name}` ).catch((e) => e)