解决hexo部署出现Spawn failed问题

报错信息

在部署时出现如下问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ hexo d
INFO Validating config
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
On branch main
nothing to commit, working tree clean
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (D:\.BNU\myblog\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (node:events:513:28)
at cp.emit (D:\.BNU\myblog\node_modules\cross-spawn\lib\enoent.js:34:29)
at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

解决办法

方案一❌

先是尝试了一下这个方案,但仍然报错:

1
2
3
4
5
6
7
8
9
10
11
##进入站点根目录
cd /usr/local/src/hexo/hanyubolg/

##删除git提交内容文件夹
rm -rf .deploy_git/

##执行
git config --global core.autocrlf false

##最后
hexo clean && hexo g && hexo d

方案二✅

接着左转右转转到了这篇文章,按照如下步骤操作,成功:

  • 打开命令行输入

    1
    ssh -T git@github.com

    得到报错

    1
    ssh: connect to host github.com port 22: Connection timed out
  • 找到 .ssh 文件夹,打开看其中是否有 config 文件,如果没有则新建一个,windows 用记事本打开编辑写入以下代码

    1
    2
    3
    4
    5
    6
    Host github.com
    User GitHub用户名
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
  • 把其中的GitHub用户名修改成自己的用户名

  • 命令行再次输入

    1
    ssh -T git@github.com
  • 出现相关提示,输入 yes 即可。