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

Angular项目部署至GitHub Pages遇问题求助

Angular部署到GitHub Pages问题解决方案

解决"NOT SUPPORTED: keyword 'id', use '$id' for schemaID"错误

该错误源于angular-cli-ghpages与当前Angular CLI版本不兼容,执行以下步骤修复:

  • 卸载冲突依赖:
    npm uninstall angular-cli-ghpages --save-dev
    
  • 安装兼容版本(Angular 16+推荐最新版,旧版本可尝试v1.0.0):
    npm install angular-cli-ghpages@latest --save-dev
    

修正angular.json部署配置

你之前配置的baseHref应为相对路径前缀,而非完整URL,修改后如下:

"deploy": {
  "builder": "angular-cli-ghpages:deploy",
  "options": {
    "baseHref": "/AngularJS-TavernCrawl/",
    "name": "wloverde",
    "email": "w.andrew.loverde@gmail.com"
  }
}

确保构建产物正确

部署前先构建生产版本,指定正确的base-href:

ng build --prod --base-href "/AngularJS-TavernCrawl/"

确认dist/Angular-js-tavern-crawl是实际构建产物目录,若目录名不符,替换为dist下的真实文件夹名称。

重新执行部署

  • 使用Angular CLI部署:
    ng deploy
    
  • 或使用npx直接部署:
    npx angular-cli-ghpages --dir=dist/Angular-js-tavern-crawl --base-href "/AngularJS-TavernCrawl/"
    

验证GitHub Pages设置

进入仓库Settings -> Pages页面,确认:

  • 源选择gh-pages分支,根目录(/)
  • 等待5-10分钟让GitHub Pages生效,若页面仍不渲染,尝试强制刷新浏览器(Ctrl+F5)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 21:42:45