执行yarn create next-app时tunneling socket建立失败问题求助
按照nextjs官方指南执行yarn create next-app firstapp创建项目时,在Git Bash中反复报错。Node.js版本为v14.17.5,确认未使用代理,但多次尝试仍失败。报错信息如下:
$ yarn create next-app firstapp
yarn create v1.22.19
[1/4] Resolving packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/create-next-app: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 8889".
info If you think this is a bug, please open a bug report with the information provided in "C:\Users\username\AppData\Local\Yarn\Data\global\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
- 检查并清除Yarn的代理配置:
先执行命令查看当前代理设置:
如果返回结果里包含yarn config get proxy yarn config get https-proxy8889端口的地址,执行以下命令清除:yarn config delete proxy yarn config delete https-proxy - 检查系统环境变量中的代理残留:
在Git Bash中执行:
若输出里有带echo $HTTP_PROXY echo $HTTPS_PROXY echo $http_proxy echo $https_proxy8889的代理地址,临时取消这些变量:
要永久移除的话,去系统环境变量设置里删除相关条目即可。unset HTTP_PROXY unset HTTPS_PROXY unset http_proxy unset https_proxy - 切换Yarn镜像(备选方案):
可以把Yarn的registry换成国内镜像试试:
设置完成后重新执行yarn config set registry https://registry.npmmirror.comyarn create next-app firstapp。 - 重启终端和网络:
清除代理配置后,关闭当前Git Bash窗口,重新打开再尝试创建项目。
内容的提问来源于stack exchange,提问作者Ekatama Ilham Prayoga

