# Error: notFound() was called but the nearest error boundary is a client component. notFound() must be called within a server component or a server-side function.

- **ID:** `nextjs/not-found-in-client-component`
- **Domain:** nextjs
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The notFound() function from 'next/navigation' is invoked inside a Client Component or a context that lacks access to the server-side request handling pipeline, causing the error boundary to be a client-side component instead of the server-side not-found page.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 14.2.0 | active | — | — |
| 15.0.0 | active | — | — |

## Workarounds

1. **Move the notFound() call to a Server Component that wraps the Client Component. Pass a prop (e.g., notFound flag) from the server to the client.** (95% success)
   ```
   Move the notFound() call to a Server Component that wraps the Client Component. Pass a prop (e.g., notFound flag) from the server to the client.
   ```
2. **If you must trigger not-found from a Client Component, use a server action that returns a redirect to the not-found page, or use the error.js file pattern with notFound() in the parent layout.** (80% success)
   ```
   If you must trigger not-found from a Client Component, use a server action that returns a redirect to the not-found page, or use the error.js file pattern with notFound() in the parent layout.
   ```

## Dead Ends

- **Wrapping the Client Component in a try-catch to catch notFound()** — notFound() throws a special NEXT_NOT_FOUND error that cannot be caught by regular try-catch blocks. It must be handled by the Next.js routing layer. (90% fail)
- **Importing notFound from 'next/client' (which doesn't exist)** — There is no 'next/client' module. The function only exists in 'next/navigation' and its behavior is server-side only. (100% fail)
- **Using notFound() inside a useEffect** — notFound() is meant for synchronous server-side execution. Calling it asynchronously in useEffect doesn't trigger the server-side not-found page. (95% fail)
