通过 npm 调整 Node.js 版本

问题重现

1
2
3
4
5
6
7
(node:2058) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2058) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:2058) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:2058) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:2058) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:2058) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency

注意:在使用 hexo g 部署博客的页面时,报出上面错误。说是错误,其实只是警告信息,如不在意,可以忽略。但懒猪有强迫症,一定要解决该问题!

查看版本

通过 npm -v 可以查看 npm 版本:

1
2
root@dusays:~# npm -v
6.14.8

通过 node -v 可以查看 Node.js 版本:

1
2
root@dusays:~# node -v
v12.18.2

安装工具

1
2
3
4
root@dusays:~# npm i -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@7.3.0
added 1 package from 2 contributors in 4.265s

注意:使用 npm i -g n 命令安装Node.js 版本管理器。

调整版本

使用 n stable 安装稳定版:

1
2
3
4
5
6
7
8
9
10
root@dusays:~# n stable
installing : node-v14.17.3
mkdir : /usr/local/n/versions/node/14.17.3
fetch : https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.xz
installed : v14.17.3 (with npm 6.14.13)

Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"

使用 n 12 安装指定版,通过 n 12.22 指定子版本:

1
2
3
4
5
root@dusays:~# n 12
installing : node-v12.22.3
mkdir : /usr/local/n/versions/node/12.22.3
fetch : https://nodejs.org/dist/v12.22.3/node-v12.22.3-linux-x64.tar.xz
installed : v12.22.3 (with npm 6.14.13)

本文链接:https://my.lmcjl.com/post/18532.html

展开阅读全文

4 评论

留下您的评论.