最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

next.js - GitHub Actions Upload Artifact "No File Path" from pnpm run build - Stack Overflow

programmeradmin0浏览0评论

I am having trouble uploading build artifacts in my GitHub Actions pipeline. The Build Next.js steps work fine, but when I try to upload the .next/ folder as an artifact, I get an error stating that no files were found with the specified path.

Here is my GitHub Actions workflow:

name: Deploy Pipeline
run-name: Deploy:${{ github.ref_name }} by @${{ github.actor }}

on:
  push:
    branches:
      - main
      - develop

jobs:
  build:
    name: Build Next.js
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '22.12.0'
      - name: Install pnpm
        run: npm install -g [email protected]
      - name: Cache Dependencies
        uses: actions/cache@v4
        id: pnpm-cache
        with:
          path: |
            ~/.pnpm-store
            node_modules
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-
      - name: Install Dependencies
        run: pnpm install --frozen-lockfile
      - name: Build Next.js
        run: pnpm run build
        env:
          NODE_ENV: production
      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: next-build
          path: .next/
          if-no-files-found: error

  deploy:
    name: Deploy to Cloudflare Pages
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
      - name: Download Build Artifacts
        uses: actions/download-artifact@v4
        with:
          name: next-build
      - name: Deploy to Cloudflare Pages
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: my-project-name
          directory: .next/
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}

The Build Next.js steps work fine, but in the Upload Build Artifacts step, I’m getting the following error:

Run actions/upload-artifact@v4
  with:
    name: next-build
    path: .next/
    if-no-files-found: error
    compression-level: 6
    overwrite: false
    include-hidden-files: false
Error: No files were found with the provided path: .next/. No artifacts will be uploaded.

I’ve tried using both absolute paths like ${{ github.workspace }}/.next and relative paths like ./.next, but neither work.

I’ve also checked that the .next/ folder exists in the repository before the upload step by running ls -la .next/, and the folder and files are there.

I watched a tutorial video () where the same steps worked perfectly, but I just can’t seem to get it to work in my pipeline.

Any idea what I might be doing wrong?

I am having trouble uploading build artifacts in my GitHub Actions pipeline. The Build Next.js steps work fine, but when I try to upload the .next/ folder as an artifact, I get an error stating that no files were found with the specified path.

Here is my GitHub Actions workflow:

name: Deploy Pipeline
run-name: Deploy:${{ github.ref_name }} by @${{ github.actor }}

on:
  push:
    branches:
      - main
      - develop

jobs:
  build:
    name: Build Next.js
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '22.12.0'
      - name: Install pnpm
        run: npm install -g [email protected]
      - name: Cache Dependencies
        uses: actions/cache@v4
        id: pnpm-cache
        with:
          path: |
            ~/.pnpm-store
            node_modules
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-
      - name: Install Dependencies
        run: pnpm install --frozen-lockfile
      - name: Build Next.js
        run: pnpm run build
        env:
          NODE_ENV: production
      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: next-build
          path: .next/
          if-no-files-found: error

  deploy:
    name: Deploy to Cloudflare Pages
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
      - name: Download Build Artifacts
        uses: actions/download-artifact@v4
        with:
          name: next-build
      - name: Deploy to Cloudflare Pages
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: my-project-name
          directory: .next/
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}

The Build Next.js steps work fine, but in the Upload Build Artifacts step, I’m getting the following error:

Run actions/upload-artifact@v4
  with:
    name: next-build
    path: .next/
    if-no-files-found: error
    compression-level: 6
    overwrite: false
    include-hidden-files: false
Error: No files were found with the provided path: .next/. No artifacts will be uploaded.

I’ve tried using both absolute paths like ${{ github.workspace }}/.next and relative paths like ./.next, but neither work.

I’ve also checked that the .next/ folder exists in the repository before the upload step by running ls -la .next/, and the folder and files are there.

I watched a tutorial video (https://www.youtube/watch?v=eeXquypcZxM) where the same steps worked perfectly, but I just can’t seem to get it to work in my pipeline.

Any idea what I might be doing wrong?

Share Improve this question edited Feb 8 at 20:17 halfer 20.3k19 gold badges109 silver badges202 bronze badges asked Feb 1 at 18:36 milkbottle0305milkbottle0305 1 1
  • 1. Add a step before the upload that outputs ls and pwd to make sure path is correct 2. Are you sure hidden files should be false? .next might be considered hidden because of the dot – shotor Commented Feb 2 at 2:27
Add a comment  | 

1 Answer 1

Reset to default 0

Try the code below first. (Have you tried anything similar?)

jobs:
  build:
    name: Build Next.js
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '22.12.0'

      - name: Install pnpm
        run: npm install -g [email protected]

      - name: Cache Dependencies
        uses: actions/cache@v4
        id: pnpm-cache
        with:
          path: |
            ~/.pnpm-store
            node_modules
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: Install Dependencies
        run: pnpm install --frozen-lockfile

      - name: Build Next.js
        run: pnpm run build
        env:
          NODE_ENV: production

      # INSERT THIS STEP HERE (After Build)
      - name: Get Absolute Path of .next
        run: echo "NEXT_PATH=$(realpath .next/)" >> $GITHUB_ENV

      ## Debugging step to check if the .next folder exists
      - name: Debug Absolute Path
        run: |
          echo "Resolved .next path: $NEXT_PATH"
          ls -la $NEXT_PATH

      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: next-build
          path: ${{ env.NEXT_PATH }}
          if-no-files-found: error

Let me know what error logs you get after try content above.

发布评论

评论列表(0)

  1. 暂无评论