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

GitHub Actions部署Angular到Firebase失败:dist目录不存在

解决GitHub Actions部署Angular到Firebase时的目录不存在错误

问题核心

部署时出现Error: Directory 'dist\arkdia-app' for Hosting does not exist.及/usr/local/bin/npx退出码1,主要是路径分隔符不兼容+GitHub Actions配置遗漏导致的。

修复步骤

1. 修正firebase.json的路径格式

GitHub Actions运行在Ubuntu(Linux)环境,需将Windows风格的反斜杠改为正斜杠:

{
  "hosting": {
    "target": "arkdia-app",
    "public": "dist/arkdia-app",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

2. 完善GitHub Actions配置

补充Node版本矩阵定义,优化依赖安装步骤:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
on:
  push:
    branches:
      - Production
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x] # 替换为项目兼容的Node版本
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - name: Install Dependencies
        run: npm install
      - name: Build Production
        run: npm run build --configuration=production
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: ${{ secrets.FIREBASE_PROJECT_ID}}
  • 新增matrix.node-version,解决原配置中变量未定义的问题
  • 移除全局安装@angular/cli和firebase-tools,使用项目本地依赖更稳定
  • 用npm run build替代直接调用ng build,确保使用本地CLI版本

3. 可选:适配Nx项目构建(如果需要)

如果是Nx管理的Angular项目,将构建命令替换为:

nx build arkdia-app --configuration=production

验证

推送修改后的配置到Production分支,重新触发工作流,确认构建和部署流程正常执行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 04:47:03