Hexo迁移注意点

2026-03-08

node-sass过时

1.安装对应的node.js版本

2.在Linux环境下可能要安装python3(有些依赖要用python编译)

# 安装 Python 3 和编译工具 (node-gyp 需要 make 和 gcc)
sudo yum install -y python3 python3-pip gcc-c++ make

3.尝试更新node-gyp

npm install node-gyp@latest --save-dev

#使用最新版编译
cd /my/hexo-workspace
#在当前项目目录下创建/修改 .npmrc 文件
echo "node-gyp=$(which node-gyp)" > .npmrc

4.重写package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "dependencies": {
    "hexo": "^7.0.0",
    "sass": "^1.69.0",
    "sass-loader": "^14.0.0" 
  },
  "devDependencies": {},
#这行配置告诉 npm,“不管哪个包想要安装 node-sass,都给我强行替换成 sass”
  "overrides": {
    "node-sass": "npm:sass@^1.69.0"
  }
}

5.重新install

cd /my/hexo-workspace
rm -rf node_modules
rm -f package-lock.json
npm cache clean --force
npm install

以上不是按顺序来,是多个解决方法。最终结果可能导致一些功能不能使用。