After countless attempts over several days and more than a thousand combinations, I am still facing the same issue with my files.
Middleware.js:
import { NextResponse } from "next/server";
export const protectedRoutes = ["/profile", "/assets", "/profile/[id]", "/"];
export const authRoutes = ["/admin/login"];
export const publicRoutes = [];
export function middleware(request) {
console.log(request.nextUrl.pathname);
if (protectedRoutes.includes(request.nextUrl.pathname)) {
console.log("test11");
return NextResponse.redirect(new URL("/not-auth", request.url));
}
}
export const config = {
matcher: ["/assets/:path*", "/admin/:path*"],
};
The Directory Structure:
- src
- app
- lib.js
- middleware.js
next.config.mjs:
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: false,
images: {
unoptimized: true,
},
output: "export",
};
export default nextConfig;
Error: ⨯ Middleware cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export
[x] Compiled /favicon.ico in 2.5s (611 modules)
GET /favicon.ico 200 in 1833ms
[] Middleware cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export
I have attempted to remove the output: "export"
parameter in the next.config.mjs
file, but the project fails to build without it.