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

使用Angular CLI 15.0.4执行ng build命令部署GitHub时遇错误求助

解决Angular CLI 15.0.4构建GitHub Pages项目的错误

以下是针对你遇到的构建错误的排查和解决步骤:

1. 替换废弃的--prod参数

Angular CLI 12+已废弃--prod参数,改用--configuration production,同时base-href只需填写仓库路径(无需完整域名),修改后的命令为:

ng build --configuration production --base-href "/movies-app/"

2. 校验angular.json生产配置

打开angular.json,确认projects -> [你的项目名称] -> architect -> build -> configurations -> production配置存在且完整,核心配置示例:

"production": {
  "outputHashing": "all",
  "sourceMap": false,
  "namedChunks": false,
  "extractLicenses": true,
  "vendorChunk": false,
  "buildOptimizer": true,
  "budgets": [
    {
      "type": "initial",
      "maximumWarning": "500kb",
      "maximumError": "1mb"
    }
  ]
}

如果配置缺失或错误,手动补充或修复。

3. 重置项目依赖

删除旧依赖文件后重新安装,解决依赖冲突问题:

rm -rf node_modules package-lock.json
npm install

4. 检查GitHub Pages仓库设置

  • 确保仓库为公开状态(私有仓库需开通GitHub Pages付费权限)
  • 在仓库的「Settings」→「Pages」中,确认源分支选择gh-pages(后续构建产物需要推送到该分支)

5. 使用专用工具简化部署

安装angular-cli-ghpages工具,自动完成构建和推送流程:

npm install -g angular-cli-ghpages

执行构建并部署:

ng build --configuration production --base-href "/movies-app/"
ngh --dir=dist/[你的项目名称]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 13:10:28