silverwolf-x/project / errors /api-routes-static-export.mdx
silverwolf-x's picture
download
raw
1.91 kB
---
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/guides/migrating/app-router-migration), which supports [Route Handlers](/docs/app/api-reference/file-conventions/route). These "API Routes" can be used to create endpoints that can be statically exported in your application.
## Useful Links
- [Static HTML export](/docs/pages/guides/static-exports) - Learn more about how you can create a static HTML export of your Next.js application.
- [Route Handlers](/docs/app/api-reference/file-conventions/route) - Learn more about how you can use Route Handlers to create endpoints that can be statically exported in your application.

Xet Storage Details

Size:
1.91 kB
·
Xet hash:
d0551122a4fae96c8fa6e7fb43cf4f88c3e956d9fb2383e86275055289abffb2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.