IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    通过 npm 调整 Node.js 版本

    Teacher Du发表于 2024-11-01 03:51:26
    love 0

    用了一段时间最新版的模板,发现问题还挺多的,虽说人生贵在折腾,但踏踏实实的写文章不香吗?所以杜老师将模板从测试版降低到正式版,重新部署的过程中报错,发现是 Node.js 的版本导致的,今天就来说下如何通过 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)


沪ICP备19023445号-2号
友情链接