In the next 13 days, the app/api folder will generate an error during the build process when nextConfig.output is "export".
In my project, I need different build types based on environment variables.
Is there any way to ignore the "api" folder during the build process when "output" is "export"?
When I run the build using nextConfig.output as "export" I get the following error:
The export encountered an error on the following path: /api/revalidate/route: /api/revalidate
import { NextRequest, NextResponse } from 'next/server'; import { revalidateTag } from 'next/cache'; export async function GET(request: NextRequest) { const tag = request.nextUrl.searchParams.get('tag'); if(tag){ revalidateTag(tag); } return NextResponse.json({ revalidated: true, now: Date.now() }); }
/** @type {import('next').NextConfig} */ const nextConfig = { output: process.env.NEXT_OUTPUT_MODE, }; module.exports = nextConfig;
Here is the repository that reproduces this error https://github.com/zeckaissue/next-export-api-crash
You can use the ignore option in the Next.js configuration file (next.config.js). You must create a configuration file if you have not already done so. Open the next.config.js file and add the following code:
I found the solution to ignore-loader. But maybe there is a better way to achieve my goal through next.js's built-in functionality
This is my updated next.config.js