vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.59k stars 26.23k forks source link

Unable to parse config export in source file error in middleware.js example #67169

Open Feli87 opened 4 days ago

Feli87 commented 4 days ago

Verify canary release

Provide environment information

NodeJs v18.17.1 Local Environment

Which example does this report relate to?

with-strict-csp

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I encountered an issue with the middleware.js example provided in the Next.js documentation. When trying to use the config export with a complex matcher configuration, I received the following error:

Unable to parse config export in source file
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compile-time.

export const config = { matcher: [ { source: "/((?!api|_next/static|_next/image|favicon.ico).*)", missing: [ { type: "header", key: "next-router-prefetch" }, { type: "header", key: "purpose", value: "prefetch" }, ], }, ], };

The syntax that works well is this: export const config = { matcher: [ '/((?!api|_next/static|_next/image|favicon.ico).*)', ], }; image

Expected Behavior

image

To Reproduce

just run the with-strict-csp example

Feli87 commented 4 days ago

I apologize if I made any mistakes in reporting this issue. I am new to contributing to the community and I am eager to learn and help improve the project. Thank you for your understanding and patience.