0%

20230129-在其他電腦重裝Hexo之疑難排解

20230129-在其他電腦重裝Hexo之疑難排解

重裝過程

  1. 確認已有安裝新版 NodeJS (有NPM)

    • node -v v18.13.0
  2. 確認已經有裝Git

  3. 安裝 Hexo

接下來執行以下指令

1
hexo v

正常應該就會顯示所有套件版本,Hexo即可運作了,但本日遇到有下列問題

問題一 Node Sass

訊息如下

1
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime

參考解法重要連結

  • node-sass安装遇到的错误

  • 修改以下檔案
    D:\Blog\GitIoSrc\package.json

  • 基本上跟前次遇到問題解法一樣,但該網站其實還有更新的解法上次沒看到

可以使用 hexo-render-dartsass 插件代替

1
"hexo-renderer-dartsass": "^0.1.2",

所以改完的 package.json 如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server"
},
"hexo": {
"version": "5.4.2"
},
"dependencies": {
"cheerio": "^1.0.0-rc.3",
"hexo": "^5.0.0",
"hexo-asset-link": "^2.1.0",
"hexo-deployer-git": "^3.0.0",
"hexo-generator-archive": "^1.0.0",
"hexo-generator-category": "^1.0.0",
"hexo-generator-index": "^2.0.0",
"hexo-generator-searchdb": "^1.3.2",
"hexo-generator-tag": "^1.0.0",
"hexo-hide-posts": "^0.1.1",
"hexo-math": "^4.0.0",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-marked": "^6.0.0",
"hexo-renderer-dartsass": "^0.1.2",
"hexo-renderer-stylus": "^2.0.0",
"hexo-server": "^2.0.0",
"lodash": "^4.17.20",
"node-sass": "^8.0.0"
}
}

改完 package.json 後,還要執行下列指令

1
npm install
1
npm audit fix --force

npm

問題二 err: Error: Cannot find module ‘./db.json’

  • 參考下列文章

Error: Cannot find module ‘./db.json’ #1720

其中的回文提到

1
This happened because somehow db.json file is missing in mime-db modules... You can create a db.json file or install mime-db module in a different location and copy db.json from there.

看起來是缺了 db.json

所以回原電腦找到該檔案並複製到 \GitIoSrc\node_modules\mime-db\db.json

  • 原因

看了最早第一次安裝 Hexo 的記錄
不知為何當時刻意把 db.json 放入 gitignore
所以本日重抓時就缺了這個檔案,所以再重新加回 git ,以後應該就不會再發生此問題了

db_json_error

db_json_ok.png

hexo_s_ok.png

問題三 git@github.com: Permission denied (publickey).

這幾天新加的 github ssh key 可以正常在一般的 repo 存取 (含 push / clone 等)
但剛剛在進行 deploy hexo 時卻出現無權限的問題

解決方式如下

需用 git bash 程式,然後依序執行 (環境是 Windows 10 網路上找的文章很多是在 linux 要注意)

1
2
3
ssh-agent bash
ssh-add ~/.ssh/github
ssh -T git@github.com

完整執行過程如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
The file will have its original line endings in your working directory
[master 1478afb] Site updated: 2023-01-29 19:05:14
4 files changed, 5 insertions(+), 5 deletions(-)
rewrite search.json (83%)
git@github.com: Permission denied (publickey).
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> (C:\_DATA\Github\GitIoSrc\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (node:events:513:28)
at cp.emit (C:\_DATA\Github\GitIoSrc\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

HUNGCHIA@DESKTOP-O82RRBG MINGW64 /c/_DATA/Github/GitIoSrc (master)
$ ssh-add ~/.ssh/github
Could not open a connection to your authentication agent.

HUNGCHIA@DESKTOP-O82RRBG MINGW64 /c/_DATA/Github/GitIoSrc (master)
$ ssh-agent bash

HUNGCHIA@DESKTOP-O82RRBG MINGW64 /c/_DATA/Github/GitIoSrc (master)
$ ssh-add ~/.ssh/github
Identity added: /c/Users/HUNGCHIA/.ssh/github (hungchia@DESKTOP-O82RRBG)

HUNGCHIA@DESKTOP-O82RRBG MINGW64 /c/_DATA/Github/GitIoSrc (master)
$ ssh -T git@github.com
Hi HankChangGSS! You've successfully authenticated, but GitHub does not provide shell access.

可以看到,一開始要 deploy 會報錯,沒權限
再來執行

1
ssh-add ~/.ssh/github 

會出現

1
Could not open a connection to your authentication agent.

找了一下解法,才知道要先用

1
ssh-agent bash

摘要結論如下

  1. 要用 git bash 加上自己指定的 ssh key (例如,此電腦登記在 Github 上的是 ~/.ssh/github )
  2. deploy 之前先用 ssh -T git@github.com 確認是否有權限,不然可能產生了一堆檔案,等了一段時間才發現沒權限
  3. \GitIoSrc\_config.yml 可以確認一下 deploy 相關的內容

gitio_ssh.png

1
2
3
4
5
6
7
8

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: git@github.com:HankChangGSS/HankChangGSS.github.io.git
branch: master

正確解法文章

解決,Ssh Add 出現 Could Not Open A Connection To Your Authentication Agent.

1
2
3
4
5
6
7
8
當執行 ssh-add 時
ssh-add ~/.ssh/<private_key_file>

如果出現錯誤訊息: Could not open a connection to your authentication agent.

執行進入 ssh bash ,就能正執行 ssh-add
ssh-agent bash
ssh-add ~/.ssh/<private_key_file>

其他參考文章及重點文字

Win10使用ssh的hexo deploy到github報錯 #3339

1
Maybe the ssh picked the wrong key file.
1
2
In you CMD, try to run ssh-add ~/.ssh/id_rsa, then try to deploy again.
Reference: #2312

using cmd,type hexo d, Error: Permission denied (publickey). #2312

補充

在我的空閒時間裡,我會不斷開發高效率、易用的小工具,讓使用者能夠享受到更好的體驗。
如果您有任何特定的服務需求,或是想要委託我開發獨一無二的程式、其他形式的合作,
歡迎透過電子郵件 E-Mail 與我聯繫。我會竭盡所能地為您提供最佳的服務。