POABOB

小小工程師的筆記分享

0%

Hexo部屬Nodejs version 14錯誤

一、Hexo deploy報錯

最近當我開始把以前使用過的Hexo拿來重新架設Blog,突然發現再deploy的情況產生了Error…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ C:\Users\poabob\Desktop\my-blog> npm run deploy

> hexo-site@0.0.0 deploy C:\Users\poabob\Desktop\my-blog
> hexo deploy

(node:10324) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10324) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:10324) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:10324) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:10324) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:10324) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
at copyFile (fs.js:2042:10)
at tryCatcher (C:\Users\poabob\Desktop\my-blog\node_modules\bluebird\js\release\util.js:16:23)
at ret (eval at makeNodePromisifiedEval (C:\Users\poabob\Desktop\my-blog\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
at C:\Users\poabob\Desktop\my-blog\node_modules\hexo-fs\lib\fs.js:144:39
  • 機器Nodejs版本是14
1
2
3
4
C:\Users\poabob\Desktop\my-blog> node -v
v14.19.1
C:\Users\poabob\Desktop\my-blog> npm -v
6.14.16

使用 hexo buildhexo cleanhexo server 也都沒有相關的錯誤提示,查看Github Issue上後才發現原來node版本太高。

二、解決辦法:安裝NVM(Node Version Manager)

  • 方法
    1. 使用 Docker
    2. 降版本到12或13
    3. 安裝NVM管理Nodejs版本

後來想想如果要寫個Blog用Docker跑Container要等有點久,降版本也不是一個治本的方式(如果一個專案發現版本過低,那又要升回去),於是我就想起以前曾經網路上有人提到的NVM-Windows可以使用(早期NVM只有支援Linux、MacOS),立馬點擊下載。

(下載列表)

如果是Linux則直接照著NVM官方Github上的README來安裝、MacOS請參考這篇文章

(下載指令)

注意:Winddows環境下安裝的話,請事先確認安裝的路徑是否有無空格,如果有的話,在使用的時候會產生exit status 145,導致無法正確使用nvm指令。

(安裝提醒)

安裝完後,將terminal全部關掉重開,就可以執行 nvm

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
C:\Users\poabob> nvm

Running version 1.1.9.

Usage:

nvm arch : Show if node is running in 32 or 64 bit mode.
nvm current : Display active version.
nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
Add --insecure to the end of this command to bypass SSL validation of the remote download server.
nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
nvm on : Enable node.js version management.
nvm off : Disable node.js version management.
nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
Set [url] to "none" to remove the proxy.
nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
nvm uninstall <version> : The version must be a specific version.
nvm use [version] [arch] : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
"newest" is the latest installed version. Optionally specify 32/64bit architecture.
nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
nvm root [path] : Set the directory where nvm should store different versions of node.js.
If <path> is not set, the current root will be displayed.
nvm version : Displays the current running version of nvm for Windows. Aliased as v.

三、NVM如何使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//安裝指定版本的 Nodejs
//nvm install 12
nvm install <version>

//刪除指定版本
//nvm uninstall 12.22.11 (要確定詳細版本)
nvm uninstall <version>

//使用指定版本的 node
//nvm uninstall 12.22.11 (要確定詳細版本)
nvm use [version]

//列出本機已安裝的版本
nvm list

注意:如果在terminal下執行 nvm use <version>nvm on 產生exit status 1,並且是亂碼,請在開啟的terminal的時候,選擇以管理員身分執行,這樣才能夠自由的切換。

1
2
3
4
5
6
C:\Users\poabob> nvm use 12.22.11
exit status 1: �z�S���������v���i���榹�ާ@�C

C:\Users\poabob> nvm on
nvm enabled
exit status 1: �z�S���������v���i���榹�ާ@�C

四、重新deploy Hexo

  1. 切換版本至12.22.11
1
2
3
4
5
6
7
C:\Users\poabob> nvm list

* 14.19.1 (Currently using 64-bit executable)
13.14.0
12.22.11
PS C:\Users\poabob> nvm use 12.22.11
Now using node v12.22.11 (64-bit)
  1. depoly成功
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
35
36
C:\Users\poabob\Desktop\my-blog> npm run deploy

> hexo-site@0.0.0 deploy C:\Users\poabob\Desktop\my-blog
> hexo deploy

INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
[master da6f936] Site updated: 2022-03-21 21:00:29
19 files changed, 434 insertions(+), 1102 deletions(-)
rename categories/{Hello => Hexo}/index.html (98%)
rewrite categories/index.html (100%)
create mode 100644 category-sitemap.xml
create mode 100644 images/hello-world_a.jpg
create mode 100644 images/hello-world_b.jpg
create mode 100644 images/hello-world_c.jpg
create mode 100644 page-sitemap.xml
create mode 100644 post-sitemap.xml
rewrite search.xml (90%)
rewrite sitemap.xml (100%)
create mode 100644 sitemap.xsl
create mode 100644 tag-sitemap.xml
rename tags/{Hello => Hexo}/index.html (97%)
rewrite tags/index.html (100%)
Enumerating objects: 51, done.
Counting objects: 100% (51/51), done.
Delta compression using up to 6 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (32/32), 322.01 KiB | 16.10 MiB/s, done.
Total 32 (delta 13), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (13/13), completed with 5 local objects.
To https://github.com/POABOB/poabob.github.io.git
4a0dd24..da6f936 HEAD -> master
Branch 'master' set up to track remote branch 'master' from 'https://github.com/POABOB/poabob.github.io.git'.
INFO Deploy done: git
------ 本文結束 ------