#invalid "GET" export

1 messages · Page 1 of 1 (latest)

lofty rover
#

Code in file
build error:

❯ bun run build
$ next build
   ▲ Next.js 15.0.3

   Creating an optimized production build ...
(node:2083) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
(node:2443) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
 ✓ Compiled successfully
   Skipping linting
   Checking validity of types  ...Failed to compile.

src/app/feed/[format]/route.ts
Type error: Route "src/app/feed/[format]/route.ts" has an invalid "GET" export:
  Type "{ params: { format: string; }; }" is not a valid type for the function's second argument.

error: script "build" exited with code 1
river pewterBOT
#

Hi @lofty rover. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the error message you've provided, it appears you're encountering a type error in your Next.js 15.0.3 project, specifically in the file src/app/feed/[format]/route.ts. The error suggests that there's an issue with the type definition of the GET function's second parameter.

In Next.js 15, there have been some changes to the typing of route handlers. The params object is now a promise, which needs to be awaited. Here's how you can fix this issue:

  1. Update your GET function to use the correct type for the second parameter:
import { NextRequest } from 'next/server';

type Params = Promise<{ format: string }>;

export async function GET(
  request: NextRequest,
  { params }: { params: Params }
) {
  const format = await params.format;
  // Rest of your code...
}

This change is documented in the Next.js 15 upgrade guide (https://nextjs.org/docs/app/building-your-application/upgrading/version-15#route-handlers):

// Before
type Params = { slug: string }

export async function GET(request: Request, segmentData: { params: Params }) {
  const params = segmentData.params
  const slug = params.slug
}

// After
type Params = Promise<{ slug: string }>

export async function GET(request: Request, segmentData: { params: Params }) {
  const params = await segmentData.params
  const slug = params.slug
}
  1. Make sure you're using the latest @types/react and @types/react-dom packages that are compatible with Next.js 15.

  2. If you're using TypeScript, ensure your tsconfig.json is up to date with the latest Next.js 15 recommendations.

If you're still encountering issues after making these changes, you might want to check if there are any other type-related problems in your codebase, or if there are any conflicts with third-party libraries.

#

@lofty rover Kapa.ai is still learning and improving, please let me know how I did by reacting below.

lofty rover
#

@river pewter error Property 'format' does not exist on type 'Params'.ts(2339) route.ts(20, 31): Did you forget to use 'await'?

type Params = Promise<{ format: string }>;

export async function GET(
  request: NextRequest,
  { params }: { params: Params },
) {
  const format = await params.format;
  const validFormats = ["rss.xml", "atom.xml", "feed.json"];

  if (!validFormats.includes(format)) {
    return NextResponse.json(
      { error: "Unsupported feed format" },
      { status: 404 },
    );
  }```
river pewterBOT
#

Let me check the knowledge base for you again. Give me one moment! :books:

#

The error you're encountering is due to the way you're trying to access the format property from the params object. In Next.js 15, the params object is a Promise, so you need to await it before accessing its properties. Here's how you can fix this issue:

type Params = Promise<{ format: string }>;

export async function GET(
  request: NextRequest,
  { params }: { params: Params },
) {
  const { format } = await params;
  const validFormats = ["rss.xml", "atom.xml", "feed.json"];

  if (!validFormats.includes(format)) {
    return NextResponse.json(
      { error: "Unsupported feed format" },
      { status: 404 },
    );
  }
  // Rest of your code...
}

The key change here is to await the entire params object and then destructure the format property from it. This is because params is a Promise that resolves to an object containing the format property.

This change aligns with the Next.js 15 upgrade guide, which shows how to handle async params in route handlers Next.js 15 Upgrade Guide (https://nextjs.org/docs/app/building-your-application/upgrading/version-15#route-handlers):

// After
type Params = Promise<{ slug: string }>

export async function GET(request: Request, segmentData: { params: Params }) {
  const params = await segmentData.params
  const slug = params.slug
}

By making this change, you should resolve the TypeScript error and correctly access the format parameter in your route handler.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: