Nuxt3+GitHub Action构建报错:dist目录不存在
解决Nuxt3 GitHub Action构建后dist目录不存在的问题
问题场景
我用GitHub Action部署Nuxt3网站,配置如下,但构建后dist目录未生成,导致推送步骤报错:
name: Generate a build and push to another branch on: push: branches: - main jobs: build: runs-on: ubuntu-latest name: Build and Push steps: - name: git-checkout uses: actions/checkout@v3 - name: pnpm-setup uses: pnpm/action-setup@v2 with: version: 6.0.2 - name: Install all dependencies run: pnpm install - name: Build run: pnpm run build # The build command of your project - name: Push uses: s0/git-publish-subdir-action@develop env: REPO: self BRANCH: build # The branch name where you want to push the assets FOLDER: dist # The directory where your assets are generated GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub will automatically add this - you don't need to bother getting a token MESSAGE: "Build: ({sha}) {msg}" # The commit message
错误日志
执行时出现以下错误:
Run s0/git-publish-subdir-action@develop env: PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin REPO: self BRANCH: build FOLDER: dist GITHUB_TOKEN: *** MESSAGE: Build: ({sha}) {msg} Cloning into '/tmp/git-publish-subdir-action-9N77GC/repo'... From https://github.com/me/mywebsite.com * [new branch] build -> build ##[info] Checking if branch build exists already data build Switched to branch 'build' ##[info] Updating branch build ##[info] Removing all files from target branch ##[info] Copying all files from /home/runner/work/mywebsite.com/mywebsite.com/dist Error: no such file or directory: /home/runner/work/mywebsite.com/mywebsite.com/dist/ at /home/runner/work/_actions/s0/git-publish-subdir-action/develop/action/dist/index.js:115:19 at Generator.next (<anonymous>) at fulfilled (/home/runner/work/_actions/s0/git-publish-subdir-action/develop/action/dist/index.js:79:58)
解决方法
问题核心是Nuxt3默认的构建输出目录不是dist,而是.output/public。有两种解决方式:
方式1:修改Nuxt配置,指定输出目录为dist
在项目根目录的nuxt.config.ts中添加build配置,让Nuxt将产物输出到dist目录:
export default defineNuxtConfig({ // 保留原有配置 build: { outDir: 'dist' // 指定输出目录为dist } })
修改后执行pnpm run build,产物会生成在dist目录,和原Action配置的FOLDER参数匹配。
方式2:直接调整GitHub Action中的目标目录
无需修改Nuxt配置,把Push步骤的FOLDER参数改成Nuxt3默认的输出目录.output/public即可:
- name: Push uses: s0/git-publish-subdir-action@develop env: REPO: self BRANCH: build FOLDER: .output/public # 替换为Nuxt3默认构建目录 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} MESSAGE: "Build: ({sha}) {msg}"
额外排查建议
如果修改后仍有问题,可以在Build步骤后添加一个目录检查步骤,确认产物是否生成:
- name: Verify build output run: ls -la .output/public # 或者ls -la dist,根据你的配置选择
内容的提问来源于stack exchange,提问作者DevonDahon
相关产品推荐
相关产品推荐

