vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.51k stars 26.22k forks source link

Github actions: Error: Page "/logs/publish/[id]" is missing "generateStaticParams()" so it cannot be used with "output: export" config. #66879

Closed maheshmnj closed 1 week ago

maheshmnj commented 1 week ago

Link to the code that reproduces this issue

https://github.com/maheshmnj/pastelog/tree/web/

To Reproduce

  1. Create a new NextJS project with a dynamic route using lates app router
project-root /
    ├──src
    │    ├── app /
    │    │   ├── models /
    │    │   │   ├── Log.ts
    │    │   ├── services /
    │    │   │   ├── LogService.ts
    │    │   ├── components /
    │    │   ├── logs /
    │    │   │   ├──publish
    │    │   │   │   ├── [id]
    │    │   │   │   |     ├── page.tsx
    │    │   │   ├──[id]
    │    │   │   │   ├── page.tsx
    │    │   └── layout.tsx
    │    │   └── global.css
    │    │   └── page.tsx
// /logs/publish/[id]/page.tsx
import Preview from '@/app/(main)/_components/Preview';
import LogService from '@/app/(main)/_services/logService';

// This is required for dynamic routing in runtime
export const dynamicParams = true;

export async function generateStaticParams() {
    const logService = new LogService();
    const logs = await logService.fetchLogs();
    return logs.map(log => ({ id: log.id }));
}
export default function PublishPage({ params }: { params: { id: string } }) {
    const { id } = params;
    return <Preview
        logId={id}
    />
};
  1. setup github actions workflow in the project .github/workflows/deploy.yaml

workflow

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
"on":
  push:
    branches:
      - web
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm ci && npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PASTELOG_ID }}"
          channelId: live
          projectId: pastelog-id
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels
  1. Make a commit

Current vs. Expected behavior

Build logs from github actions

current

flutter doctor -v ```console Run npm ci && npm run build npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v[4](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:5) are no longer supported npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported added 906 packages, and audited 907 packages in 24s 2[5](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:6)5 packages are looking for funding run `npm fund` for details 1 moderate severity vulnerability To address all issues, run: npm audit fix Run `npm audit` for details. > pastelog@0.1.0 build > next build ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache Attention: Next.js now collects completely anonymous telemetry regarding usage. This information is used to shape Next.js' roadmap and prioritize features. You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL: https://nextjs.org/telemetry ▲ Next.js 14.2.3 Creating an optimized production build ... ✓ Compiled successfully Linting and checking validity of types ... ./src/app/(main)/_components/Preview.tsx 39:8 Warning: React Hook useEffect has a missing dependency: 'fetchLogsById'. Either include it or remove the dependency array. react-hooks/exhaustive-deps ./src/app/(main)/_components/Welcome.tsx 19:8 Warning: React Hook useEffect has a missing dependency: 'tagLineWords.length'. Either include it or remove the dependency array. react-hooks/exhaustive-deps ./src/app/(main)/logs/layout.tsx 35:8 Warning: React Hook useEffect has missing dependencies: 'checkWindowSize' and 'setTheme'. Either include them or remove the dependency array. react-hooks/exhaustive-deps info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules Collecting page data ... [2024-0[6](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:7)-14T03:47:07.910Z] @firebase/firestore: Firestore (10.12.2): GrpcConnection RPC 'Listen' stream 0x85b31b9b error. Code: 3 Message: 3 INVALID_ARGUMENT: Invalid resource field value in the request. [2024-06-14T03:4[7](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:8):07.912Z] @firebase/firestore: Firestore (10.12.2): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=invalid-argument]: 3 INVALID_ARGUMENT: Invalid resource field value in the request. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend. > Build error occurred Error: Page "/logs/publish/[id]" is missing "generateStaticParams()" so it cannot be used with "output: export" config. at /home/runner/work/pastelog/pastelog/node_modules/next/dist/build/index.js:12[9](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:10)4:59 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Span.traceAsyncFn (/home/runner/work/pastelog/pastelog/node_modules/next/dist/trace/trace.js:154:20) at async Promise.all (index 6) at async /home/runner/work/pastelog/pastelog/node_modules/next/dist/build/index.js:1172:17 at async Span.traceAsyncFn (/home/runner/work/pastelog/pastelog/node_modules/next/dist/trace/trace.js:154:20) at async /home/runner/work/pastelog/pastelog/node_modules/next/dist/build/index.js:[10](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:11)95:124 at async Span.traceAsyncFn (/home/runner/work/pastelog/pastelog/node_modules/next/dist/trace/trace.js:[15](https://github.com/maheshmnj/pastelog/actions/runs/9510321644/job/26214606690#step:3:16)4:20) at async build (/home/runner/work/pastelog/pastelog/node_modules/next/dist/build/index.js:366:9) ```

expected

To build successfully, this works only when building locally

 mahesh@Maheshs-MacBook-Air-M1-3 pastelog % npx next --version
Next.js v14.2.3

Provide environment information

mahesh@Maheshs-MacBook-Air-M1-3 pastelog % npx --no-install next info

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:27 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: 9.3.0
Relevant Packages:
  next: 14.2.3 // There is a newer version (14.2.4) available, upgrade recommended! 
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: export
 ⚠ There is a newer version (14.2.4) available, upgrade recommended! 
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

### Which area(s) are affected? (Select all that apply)

Output (export/standalone)

### Which stage(s) are affected? (Select all that apply)

next build (local)

### Additional context

When we make a commit to github the job fails with the error 

ithub actions: Error: Page "/logs/publish/[id]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.



Suprisingly the `npm run build` works fine locally.
maheshmnj commented 1 week ago

Closing! I realised when building the app with github actions the environment did not have the env file hence the error. Adding a env file to github secrets and writing to workflow fixed the issue.