How It Works Features Pricing Blog Error Guides
Log In Start Free Trial
Next.js · TypeScript/React

Fix Error: Error: Dynamic server usage: force-dynamic is not allowed in generateStaticParams in Next.js

This error occurs when a statically generated page uses fetch with cache: 'no-store' or sets force-dynamic, but also exports generateStaticParams. These are contradictory: static generation requires cacheable data. Fix it by removing force-dynamic and using revalidation instead, or by removing generateStaticParams for truly dynamic pages.

Reading the Stack Trace

Error: Dynamic server usage: force-dynamic is not allowed with generateStaticParams at staticGenerationBailout (/app/node_modules/next/dist/client/components/static-generation-bailout.js:18:11) at fetchImpl (/app/node_modules/next/dist/server/lib/patch-fetch.js:172:15) at async getPost (/app/src/app/blog/[slug]/page.tsx:12:18) at async generateStaticParams (/app/src/app/blog/[slug]/page.tsx:6:15) at async buildStaticPaths (/app/node_modules/next/dist/build/utils.js:847:22) at async /app/node_modules/next/dist/build/utils.js:982:17 at async Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:103:20) at async buildAppStaticPaths (/app/node_modules/next/dist/build/utils.js:1053:14)

Here's what each line means:

Common Causes

1. force-dynamic with generateStaticParams

The page exports both generateStaticParams and force-dynamic, which are mutually exclusive configuration options.

export const dynamic = 'force-dynamic';

export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts').then(r => r.json());
  return posts.map((p: any) => ({ slug: p.slug }));
}

export default async function BlogPost({ params }) {
  const post = await fetch(`https://api.example.com/posts/${params.slug}`, {
    cache: 'no-store'
  }).then(r => r.json());
  return <article>{post.title}</article>;
}

2. fetch with no-store in static page

Using cache: 'no-store' in a fetch call within a page that has generateStaticParams makes the page dynamic, conflicting with static generation.

export async function generateStaticParams() {
  return [{ slug: 'hello' }, { slug: 'world' }];
}

export default async function Page({ params }) {
  const data = await fetch(`/api/posts/${params.slug}`, { cache: 'no-store' });
  return <div>{data.title}</div>;
}

3. Using cookies() or headers() in static page

Calling dynamic functions like cookies() in a page that exports generateStaticParams forces dynamic rendering.

import { cookies } from 'next/headers';

export async function generateStaticParams() {
  return [{ id: '1' }, { id: '2' }];
}

export default async function Page({ params }) {
  const token = cookies().get('auth');
  return <div>Post {params.id}</div>;
}

The Fix

Replace force-dynamic and cache: 'no-store' with time-based revalidation using next: { revalidate: 60 }. This keeps the page statically generated but refreshes the data every 60 seconds, combining the performance of static generation with reasonably fresh data.

Before (broken)
export const dynamic = 'force-dynamic';

export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts').then(r => r.json());
  return posts.map((p: any) => ({ slug: p.slug }));
}

export default async function BlogPost({ params }) {
  const post = await fetch(`https://api.example.com/posts/${params.slug}`, {
    cache: 'no-store'
  }).then(r => r.json());
  return <article>{post.title}</article>;
}
After (fixed)
export const revalidate = 60;

export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts').then(r => r.json());
  return posts.map((p: any) => ({ slug: p.slug }));
}

export default async function BlogPost({ params }: { params: { slug: string } }) {
  const post = await fetch(`https://api.example.com/posts/${params.slug}`, {
    next: { revalidate: 60 }
  }).then(r => r.json());
  return <article>{post.title}</article>;
}

Testing the Fix

import { render, screen } from '@testing-library/react';
import BlogPost, { generateStaticParams } from '@/app/blog/[slug]/page';

global.fetch = jest.fn();

describe('BlogPost', () => {
  beforeEach(() => {
    (fetch as jest.Mock).mockResolvedValue({
      json: () => Promise.resolve({ title: 'Hello World', content: 'Test' }),
    });
  });

  it('renders the post title', async () => {
    const Component = await BlogPost({ params: { slug: 'hello' } });
    render(Component);
    expect(screen.getByText('Hello World')).toBeInTheDocument();
  });

  it('generateStaticParams returns slugs', async () => {
    (fetch as jest.Mock).mockResolvedValue({
      json: () => Promise.resolve([{ slug: 'hello' }, { slug: 'world' }]),
    });
    const params = await generateStaticParams();
    expect(params).toEqual([{ slug: 'hello' }, { slug: 'world' }]);
  });
});

Run your tests:

npm test

Pushing Through CI/CD

git checkout -b fix/fetch-cache-static-params-conflict,git add src/app/blog/[slug]/page.tsx src/app/blog/[slug]/__tests__/page.test.tsx,git commit -m "fix: replace force-dynamic with revalidation for static pages",git push origin fix/fetch-cache-static-params-conflict

Your CI config should look something like this:

name: CI
on:
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm test -- --coverage
      - run: npm run build

The Full Manual Process: 18 Steps

Here's every step you just went through to fix this one bug:

  1. Notice the error alert or see it in your monitoring tool
  2. Open the error dashboard and read the stack trace
  3. Identify the file and line number from the stack trace
  4. Open your IDE and navigate to the file
  5. Read the surrounding code to understand context
  6. Reproduce the error locally
  7. Identify the root cause
  8. Write the fix
  9. Run the test suite locally
  10. Fix any failing tests
  11. Write new tests covering the edge case
  12. Run the full test suite again
  13. Create a new git branch
  14. Commit and push your changes
  15. Open a pull request
  16. Wait for code review
  17. Merge and deploy to production
  18. Monitor production to confirm the error is resolved

Total time: 30-60 minutes. For one bug.

Or Let bugstack Fix It in Under 2 minutes

Every step above? bugstack does it automatically.

Step 1: Install the SDK

npm install bugstack-sdk

Step 2: Initialize

import { initBugStack } from 'bugstack-sdk'

initBugStack({ apiKey: process.env.BUGSTACK_API_KEY })

Step 3: There is no step 3.

bugstack handles everything from here:

  1. Captures the stack trace and request context
  2. Pulls the relevant source files from your GitHub repo
  3. Analyzes the error and understands the code context
  4. Generates a minimal, verified fix
  5. Runs your existing test suite
  6. Pushes through your CI/CD pipeline
  7. Deploys to production (or opens a PR for review)

Time from error to fix deployed: Under 2 minutes.

Human involvement: zero.

Try bugstack Free →

No credit card. 5-minute setup. Cancel anytime.

Deploying the Fix (Manual Path)

  1. Remove force-dynamic and replace with revalidation strategy.
  2. Run the Next.js build locally to confirm static generation succeeds.
  3. Open a pull request with the caching changes.
  4. Wait for CI checks to pass on the PR.
  5. Merge to main and verify ISR works correctly in staging.

Frequently Asked Questions

BugStack verifies that static generation completes successfully, tests the revalidation strategy, runs your test suite, and confirms the build before marking it safe.

Every fix is delivered as a pull request with full CI validation. Your team reviews and approves before anything reaches production.

It depends on how fresh your data needs to be. For blog posts, 60-300 seconds is typical. For frequently changing data, consider 10-30 seconds or use on-demand revalidation with revalidateTag.

Yes. Each page can have its own caching strategy. Use generateStaticParams with revalidation for content pages and force-dynamic for personalized pages that need request-time data.