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

Next.js App目录GitHub Action CI/CD部署遇PageNotFoundError求助

问题:Next.js App目录通过GitHub Action CI/CD部署时出现PageNotFoundError: Cannot find module for page: /

尝试将Next.js的App目录通过GitHub Action CI/CD部署,但持续出现PageNotFoundError: Cannot find module for page: /错误,推测CI/CD无法读取App目录结构。以下是相关配置文件:

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    appDir: true,
  },
};

module.exports = nextConfig;

GitHub Action配置文件(nextjs.yml)

name: git push into another repo to deploy to vercel

on:
  push:
    branches: master

jobs:
  build:
    runs-on: ubuntu-latest
    container: pandoc/latex
    steps:
      - uses: actions/checkout@v2
      - name: Install mustache (to update the date)
        run: apk add ruby && gem install mustache
      - name: creates output
        run: sh ./build.sh
      - name: Pushes to another repository
        id: push_directory
        uses: cpina/github-action-push-to-another-repository@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
        with:
          source-directory: 'output'
          destination-github-username: [Seung-hwan285]
          destination-repository-name: [Team-PODO-ODEEGO-FE]
          user-email: ${{ secrets.OFFICIAL_ACCOUNT_EMAIL }}
          commit-message: ${{ github.event.commits[0].message }}
          target-branch: main
      - name: Test get variable exported by push-to-another-repository
        run: echo $DESTINATION_CLONED_DIRECTORY

排查与解决方案

1. 修正GitHub Action语法错误

destination-github-username和destination-repository-name字段不需要加方括号,方括号会被识别为字符串的一部分,导致推送目标仓库错误:

destination-github-username: Seung-hwan285
destination-repository-name: Team-PODO-ODEEGO-FE

2. 补全Node.js环境依赖

你使用的pandoc/latex容器默认没有Node.js环境,而Next.js构建必须依赖Node.js。需要在Action步骤中添加Node.js安装流程:

- name: Setup Node.js
  uses: actions/setup-node@v4
  with:
    node-version: '20' # 替换为你项目适配的Node版本
    cache: 'npm'
- name: Install project dependencies
  run: npm install

将这段代码插入到Install mustache步骤之后、creates output步骤之前。

3. 检查build.sh脚本的正确性

确认脚本中包含完整的Next.js构建逻辑:

  • 必须执行next build命令,若要指定输出到output目录,需使用next build --out output
  • 确保将next.config.js、package.json、public目录以及构建生成的.next文件夹都复制到output目录下,缺少这些文件会导致Vercel无法识别App目录结构

4. 验证目标仓库的Vercel配置

  • 确保目标仓库的next.config.js中已开启experimental.appDir: true配置
  • 检查Vercel项目的部署设置,确认未禁用App目录相关的实验性功能

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 09:31:03