Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。但使用Node.js 14.x 版本时候 启动会有报错
报错信息
Warning Accessing non-existent property
zimri@localhost% hexo s
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
(node:4470) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4470) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:4470) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:4470) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:4470) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:4470) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency常规解决方法
解决办法五花八门,其中一个比较有代表性的是把 node 降级,降到 12 就不会报这个 warning 了
brew uninstall node
brew install node@12
brew link --overwrite --force node@12但这样解决问题显然不是我的风格吗?当然不!
继续翻 Github 上的 issues,发现具体到 Hexo 这里的 warning是由于 stylus 导致的
幸运的是 stylus 在 0.54.8 版本修复了这个问题(见 #2538 )。
所以对于大多数 Hexo 用户来说,重新装一下hexo-renderer-stylus就可以愉快的 hexo s 了
yarn remove hexo-renderer-stylus
yarn add hexo-renderer-stylus究极解决方案
什么?这样的报错并没有止息?
所以还需要进一步研究!
查找报错源头
package 导致的 warnings,可以使用如下方式来看看具体是哪个 package 导致的
npx cross-env NODE_OPTIONS="--trace-warnings" hexo s问题来源nib@1.1.2
使用上边刚说的那个命令,发现这其实是 nib@1.1.2 这个包里的 stylus 引起的问题,nib 里的 dependencies如下:
{
"stylus": "0.54.5"
}Gayhub已经有人给 nib 提 issue 了,但看它最后一次更新已经是 4 years ago 了
解决问题
在 package.json 里增加 resolutions 来覆盖版本定义
"resolutions": {
"stylus": "^0.54.8"
}提到的package.json文件是Hexo项目目录下的 不是node_modules/nib下的 注意哦
然后重新 yarn install 一下就好了。
注意:使用yarn install 后才能解决,使用npm install无法解决
Q&A
Q: npm 和yarn都装上。有冲突吗,使用过程中有什么问题吗?
A: 不会有冲突,安装方式不一样,最终效果是一样的
至此 hexo 就可以和 node.js 14 开始愉快的旅程了~
【参考资料】
解决 Hexo 在使用 Node.js 14 时的 Accessing non-existent property ... | 好一则博