You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vercel部署Hugo站点时无法加载Git主题子模块求助

解决Vercel部署Hugo时子模块主题无法安装的问题
  • 检查子模块权限与仓库地址

    1. 若主题子模块是私有仓库,需在Vercel项目的「Settings」→「Git」→「Repository Access」中授权Vercel访问该子模块仓库;或者生成带repo权限的Git个人访问令牌(PAT),在Vercel项目的「Environment Variables」中添加GIT_TOKEN变量,值为该令牌。
    2. 打开项目根目录的.gitmodules文件,确保子模块使用HTTPS地址(不要用SSH),示例:
      [submodule "themes/your-theme"]
          path = themes/your-theme
          url = https://github.com/xxx/your-theme.git
      
  • 调整Vercel构建命令
    直接在构建命令中整合子模块更新操作,避免拆分到安装命令:

    • 公开仓库构建命令:git submodule update --init --recursive --force && hugo -gc(--force用于强制拉取最新子模块内容)
    • 私有仓库构建命令:git config --global url."https://${GIT_TOKEN}@github.com".insteadOf "https://github.com" && git submodule update --init --recursive && hugo -gc
      也可通过vercel.json统一配置,同时指定与本地一致的Hugo版本:
    {
      "buildCommand": "git submodule update --init --recursive && hugo -gc",
      "framework": null,
      "installCommand": "",
      "env": {
        "HUGO_VERSION": "0.120.0" // 替换为本地使用的Hugo版本
      }
    }
    
  • 清除Vercel构建缓存
    在Vercel项目的构建记录中,选择对应构建任务点击「Redeploy」,勾选「Clear build cache」后重新部署,避免旧缓存干扰子模块更新。

内容的提问来源于stack exchange,提问作者piedpipr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 16:00:04