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

Fix Error: Error: invariant: static generation store missing in revalidateTag in Next.js

This error occurs when revalidateTag or revalidatePath is called outside a server action or route handler context. These functions require the static generation store which is only available during server-side request processing. Fix it by calling revalidation functions inside a server action or API route handler.

Reading the Stack Trace

Error: invariant: static generation store missing in revalidateTag at revalidateTag (/app/node_modules/next/dist/server/web/spec-extension/revalidate-tag.js:12:15) at updatePost (/app/src/app/actions.ts:24:3) at async eval (webpack-internal:///./src/components/EditForm.tsx:18:5) at async callServer (/app/node_modules/next/dist/client/app-call-server.js:18:16) at async handleSubmit (webpack-internal:///./src/components/EditForm.tsx:15:7) at async HTMLFormElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:4164:14) at async Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:4213:16) at async dispatchEvent (node_modules/react-dom/cjs/react-dom.development.js:10812:5)

Here's what each line means:

Common Causes

1. Missing 'use server' directive

The function calling revalidateTag is not marked as a server action, so it runs in the wrong context.

// src/app/actions.ts
import { revalidateTag } from 'next/cache';

// Missing 'use server' directive
export async function updatePost(id: string, data: FormData) {
  await db.post.update({ where: { id }, data: { title: data.get('title') } });
  revalidateTag('posts');
}

2. Calling revalidation in a client component

revalidateTag is imported and called directly in a client component instead of through a server action.

'use client';
import { revalidateTag } from 'next/cache';

export function EditButton() {
  return <button onClick={() => revalidateTag('posts')}>Refresh</button>;
}

3. Calling revalidation in a utility function

A shared utility function calls revalidateTag but is invoked from a context that does not have the server store.

// src/lib/cache-utils.ts
import { revalidateTag } from 'next/cache';

export function invalidatePostCache() {
  revalidateTag('posts'); // No server context when called from client
}

The Fix

Add the 'use server' directive at the top of the file to mark all exported functions as server actions. This ensures Next.js provides the static generation store when the function executes, allowing revalidateTag to work correctly.

Before (broken)
// src/app/actions.ts
import { revalidateTag } from 'next/cache';

export async function updatePost(id: string, data: FormData) {
  await db.post.update({ where: { id }, data: { title: data.get('title') } });
  revalidateTag('posts');
}
After (fixed)
'use server';

import { revalidateTag } from 'next/cache';

export async function updatePost(id: string, data: FormData) {
  await db.post.update({ where: { id }, data: { title: data.get('title') as string } });
  revalidateTag('posts');
}

Testing the Fix

import { updatePost } from '@/app/actions';
import { revalidateTag } from 'next/cache';

jest.mock('next/cache', () => ({
  revalidateTag: jest.fn(),
}));

jest.mock('@/lib/db', () => ({
  db: {
    post: {
      update: jest.fn().mockResolvedValue({ id: '1', title: 'Updated' }),
    },
  },
}));

describe('updatePost server action', () => {
  it('updates the post and revalidates the cache tag', async () => {
    const formData = new FormData();
    formData.set('title', 'New Title');
    await updatePost('1', formData);
    expect(revalidateTag).toHaveBeenCalledWith('posts');
  });

  it('calls db.post.update with correct arguments', async () => {
    const { db } = require('@/lib/db');
    const formData = new FormData();
    formData.set('title', 'Updated Title');
    await updatePost('1', formData);
    expect(db.post.update).toHaveBeenCalledWith({
      where: { id: '1' },
      data: { title: 'Updated Title' },
    });
  });
});

Run your tests:

npm test

Pushing Through CI/CD

git checkout -b fix/revalidation-use-server-directive,git add src/app/actions.ts src/app/__tests__/actions.test.ts,git commit -m "fix: add 'use server' directive to enable revalidateTag",git push origin fix/revalidation-use-server-directive

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. Add the 'use server' directive to the actions file.
  2. Run the test suite locally to confirm revalidation works.
  3. Open a pull request with the server action fix.
  4. Wait for CI checks to pass on the PR.
  5. Merge to main and verify cache revalidation works in staging.

Frequently Asked Questions

BugStack verifies the server action executes in the correct context, confirms revalidation triggers properly, runs your tests, and validates 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.

revalidateTag invalidates all cached fetch requests tagged with a specific string. revalidatePath invalidates the cache for a specific URL path. Both require a server action or route handler context.

Yes. API routes in the App Router (route.ts files) have the static generation store available. You can call revalidateTag inside a GET, POST, or other handler function.