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

GitHub Action中tsc执行后无dist文件夹问题求助

问题:GitHub Action中tsc执行后未生成dist文件夹

本地执行tsc可正常将代码编译至./dist目录,但在GitHub Action流水线中,执行icrawl/action-tsc@v1后,目录中找不到预期的dist文件夹。相关配置如下:

tsconfig.json配置

{
  "compilerOptions": {
    "strict": true,
    "outDir": "dist",
    "target": "ES6",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "module": "commonjs"
  },
  "include": ["./src/**/*"]
}

GitHub Action相关代码

name: Build & Deploy

on:
  push:
    branches: ['deploy']

  pull_request:
    branches: ['deploy']

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]

    steps:
      - uses: actions/checkout@v3
      - name: install node v18
        uses: actions/setup-node@v1
        with:
          node-version: 18
      - name: yarn install
        run: yarn install
      - name: tsc
        uses: icrawl/action-tsc@v1
      - name: List files in the workspace repository
        run: |
          ls ${{ github.workspace }}
      - name: List files in ./
        run: |
          ls ./
      - uses: a7ul/tar-action@v1.1.0
        with:
          command: c
          cwd: './'
          files: |
            citygml-tools-2.1.0/
            src/
#dist does not exist!?
            dist/
            tmp/
            .dockerignore
            Dockerfile
            package.json
            tsconfig.json
            captain-definition
          outPath: deploy.tar

      - name: Deploy App to CapRover
        uses: caprover/deploy-from-github@v1.0.1
        with:
          server: '${{ secrets.CAPROVER_PFCACE_SERVER }}'
          app: '${{ secrets.APP_NAME }}'
          token: '${{ secrets.APP_PFCACE_TOKEN }}'

问题原因

icrawl/action-tsc@v1这类第三方Action可能存在执行上下文不匹配的问题:它可能没有使用项目本地安装的TypeScript版本,或者没有在仓库根目录读取tsconfig.json,导致编译过程没有按照预期输出到dist目录,甚至可能编译失败但未抛出明显错误。

解决方案

1. 使用项目本地的tsc命令替代第三方Action

直接调用项目依赖中的tsc,避免环境不一致问题:

  • 如果package.json中有build脚本(比如"build": "tsc"),替换原有tsc步骤为:
- name: Run build script
  run: yarn build
  • 也可以直接用npx调用本地tsc:
- name: Execute tsc build
  run: npx tsc

2. 显式指定tsconfig路径(可选)

为确保编译时读取正确的配置文件,可在命令中明确指定:

- name: Execute tsc with explicit config
  run: npx tsc --project ./tsconfig.json

3. 验证工作目录(可选)

在编译步骤前添加目录检查,确认当前路径为仓库根目录:

- name: Check current working directory
  run: pwd

总结

使用项目本地的TypeScript工具执行编译,能最大程度保证和本地开发环境一致,避免第三方Action带来的环境差异问题。调整后重新运行流水线,dist目录应该会正常生成。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 08:10:04