Could not locate the repository for “https://github.com/vercel/next-learn-starter/tree/master/lear

Next.js 入门 Could not locate the repository for "https://github.com/vercel/next-learn-starter/tree/master/learn-starter". Please check that the repository exists and try again.报错解决问题

Setup - 创建 Next.js 应用程序 | Learn Next.js | Next.js中文网 在启动页面跟着学习的时候

运行下面这行命令

npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn-starter/tree/master/learn-starter"

结果提示:

Could not locate the repository for "https://github.com/vercel/next-learn-starter/tree/master/learn-starter". Please check that the repository exists and try again.

如下所示:

然后看看是不是网络问题,通过curl去查看返回的数据

curl -I https://api.github.com/users/octocat

返回的数据

HTTP/2 200 
date: Mon, 24 Feb 2025 01:52:31 GMT
content-type: application/json; charset=utf-8
cache-control: public, max-age=60, s-maxage=60
vary: Accept,Accept-Encoding, Accept, X-Requested-With
etag: W/"4b3085720f9aa9f6444b7f3e95d1a8b1f74ea239470f2afa3ba14f11e9145cc8"
last-modified: Sat, 22 Feb 2025 12:25:16 GMT
x-github-media-type: github.v3; format=json
x-github-api-version-selected: 2022-11-28
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
server: github.com
accept-ranges: bytes
x-ratelimit-limit: 60
x-ratelimit-remaining: 54
x-ratelimit-reset: 1740365430
x-ratelimit-used: 6
x-ratelimit-resource: core
content-length: 1350
x-github-request-id: 587D:1369F4:1A1B5A:21E8DF:67BBD0DF

https://github.com/vercel/next-learn/issues/60github上的next-learn项目的issues里找到了解决这个问题的答案

原因是master分支不再存在,改成了main分支,所以需要用下面这行命令去执行

npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/main/basics/learn-starter"

运行完成之后,可以看到成功下载对应的代码,并提示

cd nextjs-blog
npm run dev


运行上述命令之后,在浏览器输入提示的ip地址,可以看到如下界面:

总结

用下面这行命令替换掉即可。

npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/main/basics/learn-starter"