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

本地npm run build正常但Github Actions构建失败求助

Vite项目本地构建正常但Github Actions构建失败

我用ViteJS开发应用,本地执行npm run build可正常完成构建,但在Github Actions中执行该命令时构建失败。其他任务(lint-format、test)均执行通过,仅build任务出错。

Github Actions工作流配置

name: CI

on: push
jobs:
  lint-format:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [16.x]
    steps:
      - name: Checkout Commit
        uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
      - name: Install deps
        run: |
          npm ci
      - name: Run lint
        run: |
          npm run lint
      - name: Run prettier
        run: |
          npm run format
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [16.x]
    steps:
      - name: Checkout Commit
        uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
      - name: Install deps
        run: |
          npm ci
      - name: Run test
        run: |
          npm run test
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [16.x]
    needs: [lint-format, test]
    steps:
      - name: Checkout Commit
        uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
      - name: remove node_modules
        run: rm -rf node_modules/
      - name: Install deps
        run: |
          npm ci
      - name: Run build
        run: |
          npm run build

TypeScript配置(tsconfig.json)

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "paths": {
      "@/*": ["src/*"]
    },
    "baseUrl": "."
  },
  "include": ["src","src/**/*.ts", "tests/**/*.ts",".eslintrc.cjs", "vitest.config.ts"],
  "exclude": ["node_modules", ".vscode"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

构建错误截图

构建错误截图

请问是什么原因导致的?我的工作流是否缺失了配置?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 02:45:18