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

部署Angular应用至GitHub Pages遇Unknown argument: base-href错误求助

解决Angular部署GitHub Pages时的Unknown argument: base-href错误

出现这个错误的核心原因是参数传递方式或格式不正确,以下是几种可行的解决方法:

方法1:使用驼峰格式的插件参数

angular-cli-ghpages插件本身支持驼峰命名的--baseHref参数,替换原短横线格式即可:

ng deploy --baseHref=https://rejkid.com.github.io/ScheduleMeFrontEnd/

方法2:通过分隔符传递build环节参数

如果要把--base-href传递给Angular的build命令(而非deploy插件),需要用--作为分隔符,将build参数放在后面:

ng deploy -- --base-href=https://rejkid.com.github.io/ScheduleMeFrontEnd/

方法3:在angular.json中预配置baseHref

直接在项目配置文件里指定baseHref,后续deploy无需再传参数:

  1. 打开angular.json,找到projects -> 你的项目名 -> architect -> build -> options
  2. 添加或修改baseHref字段:
    "options": {
      "baseHref": "https://rejkid.com.github.io/ScheduleMeFrontEnd/",
      // 其他已有配置...
    }
    
  3. 执行简化的deploy命令:
    ng deploy
    

额外注意事项

  • 确认angular-cli-ghpages版本与你的Angular CLI版本兼容,Node.js 14.20.0可指定适配版本安装,例如:npm i angular-cli-ghpages@1.0.0(根据实际Angular版本调整)
  • 确保GitHub仓库名称与URL路径完全一致,避免路径不匹配导致部署后页面无法访问

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 10:38:16