rsnext/errors/api-routes-static-export.mdx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
1.9 KiB
Text
Raw Normal View History

---
title: Understanding "API Routes in Static Export" Warning in Next.js
description: This document explains the "API Routes in Static Export" warning in Next.js and offers steps to resolve it.
---
## Why This Warning Occurred
The "API Routes in Static Export" warning is typically raised when an `exportPathMap` path is matched to an API route while trying to statically export a Next.js application via the `next export` command. This command disables API routes as it is designed for a static-only setup.
Running `next export` is not necessary to make your application static. Pages in your application that do not have server-side data dependencies will be automatically statically optimized when you run `next build`. This includes pages powered by `getStaticProps`.
## Possible Ways to Fix It
To resolve this issue, you have two main options:
1. Use the `next build` command instead of `next export` if you're deploying your application on platforms that don't require `next export`. For example, [Vercel](https://vercel.com) is a popular hosting platform for Next.js applications that supports this feature.
2. If you still need to use `next export`, make sure to remove any paths that use API routes from your `exportPathMap` in your `next.config.js` file.
3. Consider [incrementally adopting the App Router](/docs/app/building-your-application/upgrading/app-router-migration), which supports [Route Handlers](/docs/app/building-your-application/routing/route-handlers). These "API Routes" can be used to create endpoints that can be statically exported in your application.
## Useful Links
- [Static HTML export](/docs/pages/building-your-application/deploying/static-exports) - Learn more about how you can create a static HTML export of your Next.js application.
Docs: Document caching mechanisms (#52514) This PR document the caching semantics in Next.js, how they interact, and what APIs affect them. We're also taking the opportunity to consolidate terminology, remove duplicate content, and update sections of the docs that relate to caching. ### Documentation - [x] Create a new section for caching - [x] Explain how the different caching mechanisms work - [x] Request Memoization (React Cache) - [x] Persistent Data Cache - [x] Persistent Full Route Cache - [x] In-memory, client-side Router Cache - [x] Document how different APIs affect caching - [x] Document cache interactions - [x] Clean up stale information in the other docs sections - [x] Routing Section - [x] Move advanced navigation topics from fundamentals to **How Navigation Works** section - [x] Rewrite the **How Navigation Works** section - [x] Rendering Section - [x] Simplify fundamentals page - [x] Rewrite the **Static and Dynamic Rendering** pages - [ ] ~Create a page to explain how **Client and Server Components** are rendered~. Moved to this PR: https://github.com/vercel/next.js/pull/51579 - [x] Data fetching section - [x] Consolidate data fetching story for fetching, caching, and revalidating - [x] Clarify data fetching story with 3rd party libraries and React `cache` - [x] Create **Data Fetching Patterns** page - [x] Document other related behaviors: - [x] Update information on scroll position for back/forward navigation - [x] Remove the concepts of **soft and hard navigation** - [x] Remove the concepts of **static and dynamic data fetching** - [x] Use consistent terminology **runtime** 👉🏼 **request time**. Runtime for Edge and Node.js, request time to describe when dynamic stuff happens - [x] `generateStaticParams` being able to seed the Full Route Cache - [x] Polish 💅🏼 --- ### Related PRs: - Diagrams: https://github.com/vercel/front/pull/24142 - Redirects: https://github.com/vercel/front/pull/24179
2023-07-31 19:03:26 +02:00
- [Route Handlers](/docs/app/building-your-application/routing/route-handlers) - Learn more about how you can use Route Handlers to create endpoints that can be statically exported in your application.