与天斗,与地斗,与故障斗,其乐融融。

整个博客部署过程耗尽了很多时间,这里进行简单的复盘。

最开始的问题

In file included from ../src/binding.cpp:3:0:
../src/sass_context_wrapper.h:8:10: fatal error: sass/context.h: No such file or directory
#include <sass/context.h>
^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1

最开始查看日志,然后直接在网络上进行搜索,通过安装node-sass解决了问题。
npm install node-sass --registry=http://registry.npm.taobao.org --sass-binary-site=http://npm.taobao.org/mirrors/node-sass;

接着的问题

进行上述修改后,发现GitHub Actions 虽然显示没有问题,但是博客无法正常加载css样式,显得很乱。查看日志发现如下报错:

ERROR Plugin load failed: hexo-renderer-sass
Error: Missing binding /github/workspace/node_modules/hexo-renderer-sass/node_modules/node-sass/vendor/linux_musl-x64-79/binding.node
Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 13.x

Found bindings for the following environments:
- Linux 64-bit with Node.js 14.x

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
at module.exports (/github/workspace/node_modules/hexo-renderer-sass/node_modules/node-sass/lib/binding.js:15:13)

这里我首先添加npm rebuild node-sass进 workflow 文件里面,但仍旧没用。

经过好久的折腾尝试,我终于意识到上面报错日志里的 Node.js 版本问题

版本问题

Github Actions 的 Ubuntu环境 里的 Node.js 版本为 14.15.4

而部署博客的使用的Action sma11black/hexo-action 的docker容器 Node.js版本却为 node:12-buster-slim

而我本地的 Node.js 版本为 v12.16.1

更新版本

  1. 随后,我将本地电脑的 Node.js 升级为 v14.15.5,并重新安装了 node-sass 包;

    npm install node-sass --registry=http://registry.npm.taobao.org --sass-binary-site=http://npm.taobao.org/mirrors/node-sass;

  2. 修改了 sma11black/hexo-action里的node版本,并在GitHub Marketplace上进行了发布

  3. 指定GitHub Actions 运行版本为 ubuntu-18.04

总结

  • 不断尝试,直至问题解决;
  • 仔细看故障log往往可以缩短解决问题需要耗费的时间
  • 与天斗,与地斗,与故障斗,其乐融融。