Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse config export in source file #63896

Closed
r34son opened this issue Mar 30, 2024 · 12 comments · Fixed by #64678
Closed

Unable to parse config export in source file #63896

r34son opened this issue Mar 30, 2024 · 12 comments · Fixed by #64678
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js.

Comments

@r34son
Copy link

r34son commented Mar 30, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/wonderful-haibt-mw8z7p

To Reproduce

export matcher config from middleware like this:

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - monitoring (sentry tunnel route)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     * - sitemap.xml (sitemap file)
     * - robots.txt (robots file)
     * - manifest.webmanifest (manifest file)
     * - icon (icons)
     */
    {
      source:
        '/((?!api|monitoring|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|manifest|icon).*)',
      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],
    },
  ],
};

Current vs. Expected behavior

next dev --turbo throws warnings:

 ⚠ ./src/middleware.ts
Unable to parse config export in source file
The exported configuration object in a source file need to have a very specific format from which some properties can be statically parsed at compiled-time.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: N/A
  pnpm: 8.15.5
Relevant Packages:
  next: 14.2.0-canary.49 // Latest available version is detected (14.2.0-canary.49).
  eslint-config-next: 14.1.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Middleware / Edge (API routes, runtime), Turbopack (--turbo)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

PACK-2899

@r34son r34son added the bug Issue was opened via the bug report template. label Mar 30, 2024
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js. labels Mar 30, 2024
@kamalciirs
Copy link

Can you please check the issue reproduce example link is unavailable.

image

@r34son
Copy link
Author

r34son commented Apr 1, 2024

Can you please check the issue reproduce example link is unavailable.

Updated link

@balazsorban44 balazsorban44 added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Apr 3, 2024
@balazsorban44
Copy link
Member

It looks like the parsing is incomplete at:

JsValue::Array { items, .. } => {
for item in items {
if let Some(matcher) = item.as_str() {
matchers.push(matcher.to_string());
} else {
invalid_config(
"The matcher property must be a string or array \
of strings",
value,
);
}
}
}
🤔 It should also allow objects as an item of the matchers array.

@Gawdfrey
Copy link

I bumped into this issue after upgrading to v14.2 just now. I have almost the exact same config as OP.
I guess this makes it so that the matcher is not respected and it applies to all routes? 🤔

@ivandamyanov
Copy link

I get the same issue when turning on --turbo with nextjs 14.2.1 with this matcher:

[
    {
      source: '/((?!api|_next/static|_next/image|__nextjs|.*\\..*|favicon.ico|auth/).*)',
      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],
    },
]

@biohackerellie
Copy link

+1, have the exact same issue, exact same config

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" },
      ],
    },
  ],
};
Unable to parse config export in source file 
The exported configuration object in a source file need to have a very specific format from which some properties can be statically parsed at compiled-time.

@jenewland1999
Copy link
Contributor

+1, have the exact same issue with same config too. Seems to be a 14.2 specific thing.

@mwawrusch
Copy link


export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     */
    {
      source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],
    },
  ],
}

14.2.1

@timneutkens
Copy link
Member

We've opened a fix here: #64678

timneutkens pushed a commit that referenced this issue Apr 23, 2024
### What

- closes #63896

PR implements parsing JSValue for the matcher config if given item is an
object. We had those types already declared in place but somehow parsing
ignores it.
@mwawrusch
Copy link

As always you guys rock. Thank you

@jenewland1999
Copy link
Contributor

Thanks @timneutkens and team! Appreciate the fix!

Copy link
Contributor

github-actions bot commented May 9, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label May 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Runtime Related to Node.js or Edge Runtime with Next.js. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants