记录了如何解决hexo部署过程中出现的警告和报错

警告

warning: LF will be replaced by CRLF in xxx.html.

原因

各系统行结束符/换行符(EndOfLine)不同,在跨平台协作时行结束符被替换,空白符(即空格符,制表符,换行符)产生差异,引起警告

中文名 英文名 缩写 转义符号 ASCII码
回车 Carriage Return CR \r 0x0D(13)
换行 Line Feed LF \n 0x0A(10)

Dos,Windows,WSL

使用回车(CR)和换行(LF)两个字符来结束一行 CRLF “\r\n”

Unix,Linux,Mac

使用换行(LF)一个字符来结束一行 LF “\n”

注意

Mac OS 在 OS X 以前每行结尾是"\r", 现在每行结尾是 “\n”

git config core.autocrlf

设置当前Git中对待行结束符的方式

存在 true input false 三种设置

git config --global core.autocrlf false

允许提交包含混合换行符的文件,提交时不进行转换

警告

warning: Accessing non-existent property ‘xxx’ of module exports inside circular dependency

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

本机环境 Node.js 版本号为 v16.13.2

搜集到的解决方案

方案一

将 Node.js 降级至版本 12

卸载当前Node.js ,安装nvm-windows管理工具

nvm ls available

查看 可用的 Node.js 版本

nvm install 12.20.0

安装版本 v12.20.0,可自行选择相应版本进行安装

nvm ls

查看已安装的所有版本

nvm use 12.20.0

选择本地运行的 Node.js 版本,例如 12.20.0。

补充:

nvm uninstall 12.20.0

卸载选定版本的 Node.js

此方法治标不治本,本人未进行相应尝试

方案二

stylus/nib 更新缓慢引起的警告

由于历史原因,Hexo 开发者无法放弃对 stylus/nib#350 的依赖,目前没有更好的解决方案,希望后续版本可以完美解决此警告

错误

err: Template render error: (unknown path)
Error: unexpected end of comment

err: Template render error: (unknown path)
    Error: unexpected end of comment
      at Object._prettifyError (C:\Users\ba2in9a\Documents\blog\node_modules\nunjucks\src\lib.js:36:11)
      at Template.render (C:\Users\ba2in9a\Documents\blog\node_modules\nunjucks\src\environment.js:538:21)
      at Environment.renderString (C:\Users\ba2in9a\Documents\blog\node_modules\nunjucks\src\environment.js:380:17)
      at C:\Users\ba2in9a\Documents\blog\node_modules\hexo\lib\extend\tag.js:236:16
      at tryCatcher (C:\Users\ba2in9a\Documents\blog\node_modules\bluebird\js\release\util.js:16:23)

原因

文章内容中存在未被代码块包含的#}造成模板渲染错误

解决

#}添入代码块或者删除即可