Loading... Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。但使用Node.js 14.x 版本时候 启动会有报错 <!--more--> ## 报错信息 > Warning Accessing non-existent property ```shell 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 了 ```shell brew uninstall node brew install node@12 brew link --overwrite --force node@12 ``` 但这样解决问题显然不是我的风格吗?当然不! 继续翻 Github 上的 issues,发现具体到 Hexo 这里的 warning是由于 [stylus](https://github.com/stylus/stylus) 导致的 幸运的是 stylus 在 0.54.8 版本修复了这个问题(见 [#2538](https://github.com/stylus/stylus/pull/2538) )。 所以对于大多数 Hexo 用户来说,重新装一下`hexo-renderer-stylus`就可以愉快的 `hexo s `了 ```shell yarn remove hexo-renderer-stylus yarn add hexo-renderer-stylus ``` ## 究极解决方案 什么?这样的报错并没有止息? 所以还需要进一步研究! ### 查找报错源头 `package `导致的 `warnings`,可以使用如下方式来看看具体是哪个 `package` 导致的 ```shell npx cross-env NODE_OPTIONS="--trace-warnings" hexo s ``` ### 问题来源nib@1.1.2 使用上边刚说的那个命令,发现这其实是 nib@1.1.2 这个包里的 stylus 引起的问题,nib 里的 `dependencies`如下: ```json { "stylus": "0.54.5" } ``` Gayhub已经有人给 `nib` 提 `issue` 了,但看它最后一次更新已经是 `4 years ago` 了 ### 解决问题 在 `package.json` 里增加 `resolutions` 来覆盖版本定义 ```json "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 ... | 好一则博 ](https://www.haoyizebo.com/posts/710984d0/) 最后修改:2024 年 01 月 25 日 © 转载自他站 打赏 赞赏作者 支付宝微信 赞 69 如果觉得我的文章对你有用,请随意赞赏