Next.js can't recognize the exported config field in route "/src/middleware":
main
date
Jul 30, 2024
slug
nextjs-cant-recognize-the-exported-config-field-in-route
author
status
Public
tags
Nextjs
summary
type
Post
thumbnail
category
Development
updatedAt
Oct 12, 2025 10:45 AM
Unsupported spread operator in the Object Expression at "config".
uncaughtException [Error: EPERM: operation not permitted, open 'C:\workspaces\unisurvey-v2\application\apps\platform\.next\trace']

import type { NextRequest } from "next/server"; import { NextResponse } from "next/server"; const isDevelop = process.env.NODE_ENV === "development"; const originPath = isDevelop ? process.env.NEXT_PUBLIC_DEVELOPMENT_REDIRECT_URL : process.env.NEXT_PUBLIC_PRODUCTION_REDIRECT_URL || ""; const HOST = isDevelop ? process.env.NEXT_PUBLIC_DEVELOPMENT_PLATFORM_SERVER_HOST : process.env.NEXT_PUBLIC_PRODUCTION_PLATFORM_SERVER_HOST; export const isValidateProjectBySnum = async (SNUM: number, token: string) => { const url = `${HOST}/project/access/${SNUM}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${token}`, }, }); const data = await response.json(); return data.result; }; export async function middleware(request: NextRequest) { const { pathname } = request.nextUrl; const token = request.cookies.get("token")?.value; // 결과 페이지일 경우 검사 if (pathname.startsWith("/result/")) { const resultMatch = pathname.match(/^\/result\/(\d+)$/); // 유효하지 않을 경우 if (!resultMatch) return NextResponse.redirect(`${originPath}`); if (resultMatch) { const snum = resultMatch[1]; if (!snum || isNaN(+snum)) return NextResponse.redirect(`${originPath}`); if (token) { const isValid = await isValidateProjectBySnum(+snum, token); if (!isValid) return NextResponse.redirect(`${originPath}`); } } } return NextResponse.next(); } // 미들웨어가 실행될 경로 설정 const matcher = [ "/result/:snum*", "/((?!healthy|api|_next/static|_next/image|favicon.ico).*)", ]; export const config = { matcher, };
next build 시 위와 같은 에러로 빌드가 되지 않음
Unsupported spread operator in the Object Expression at "config".
메세지와 보이는 것 같이 middleware config가 잘못됨
export const config = { matcher: [ "/result/:snum*", "/((?!healthy|api|_next/static|_next/image|favicon.ico).*)", ], };
config를 위와 같이 수정