解决 Hexo 使用 Node.js 14 Accessing non-existent property问题

1,978 阅读1分钟

最近在用HEXO捣鼓博客的时候,遇到一个问题:

$ hexo -s                              
(node:87224) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:87224) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:87224) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:87224) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:87224) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:87224) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency

环境:

hexo:"5.4.0"

Node:"v14.17.0"

hexo-renderer-stylus:"^2.0.1"

复现:

只要在hexo中使用到hexo-renderer-stylus,就会出现上面的警告,不去管他也能正常使用,但是看起来不舒服。

解决办法1:

将node从14降级到12,警告消失,但是这样容易引起其他依赖问题,算是把问题掩盖了,不采纳。

解决办法2:

Hexo 这里的 warning是由于stylus导致的,幸运的是stylus 在 0.54.8 版本修复了这个问题,所以对于 Hexo 用户来说,重新装一下hexo-renderer-stylus,就可正常使用。

但是我重装之后发现还是会报警告,继续追溯源头,发现是这其实是nib这个包里的 stylus 引起的问题,而这个包已经很久没更新了。

2.1 将hexo-renderer-stylus更新到2.0.1

2.2 将stylus 从0.54.5更新到0.54.8

"resolutions": {
    "stylus": "^0.54.8"
  },

npm install 或 yarn install

如果还是有警告,可以cd node_module/nib,强行把它的stylus升级到0.54.8(不推荐这么做)

成功消除Warning!