question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next 13: Missing Types for generateStaticParams

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 Binaries: Node: 16.18.0 npm: 8.19.2 Yarn: 1.22.19 pnpm: 7.13.4 Relevant packages: next: 13.0.0 eslint-config-next: 13.0.0 react: 18.2.0 react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

No response

Describe the Bug

A next 13 app with typescript and generateStaticParams can not be build. The following code works in dev mode, but fails on build:

import { use } from "react";
import { fetchPeople, fetchPeoples } from "../../../lib/people";

type Params = {
  id: string;
};

type Props = {
  params: Params;
};

const People = ({ params }: Props) => {
  const people = use(fetchPeople(params.id));
  return (
    <>
      <h1>{people.name}</h1>
    </>
  );
};

export const generateStaticParams = async (): Promise<Params[]> => {
  const peoples = await fetchPeoples();

  const result = peoples.map((people) => ({
    id: people.id,
  }));

  return result;
}

export default People;

The build fails with the following error:

Type error: Page "app/people/[id]/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
        Expected "Props", got "PageProps".
          Invalid configuration:
            Expected "Params", got "PageParams | undefined".
              Expected "Params", got "undefined".

Sadly i was not able to find the mentioned types of the error.

Have a look at the following discussions for more informations:

Expected Behavior

The example above can be build or the required types are exported.

Link to reproduction

https://github.com/sdorra/next-13-missing-types

To Reproduce

Run pnpm build in the example repository

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:14
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
thaddeuscleocommented, Nov 17, 2022

I’m currently running "next": "^13.0.3" and i still facing same issue when executing npm run build. this line of code cause the build to fail:

export default async function RoomDashboard({
  searchParams,
}: {
  searchParams: { currentPage: number };
}) {
   // page logic
}

This is the error when executing npm run build:

Type error: Page "app/room/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
        Expected "{ searchParams: { currentPage: number; }; }", got "PageProps".

I didn’t face any problem during dev(npm run dev), I’m not sure whether it’s my fault or the feature got some bugs during build time.

NextJS 13 is dope 🚀 , but there is something can be polish. thank you Nextjs Dev member have a nice day 😄. I really hope this can be sort out soon…

8reactions
czterystaczwartycommented, Oct 26, 2022

I’m facing the same problem during build:

type PageParams = {
  slug: string;
};

type PageProps = {
  params: PageParams;
};

export const dynamicParams = true;

export async function generateStaticParams(): Promise<PageParams[]> {
  const payload = await getNodes();

  return payload.nodes.map((node) => ({
    slug: node.path
  }));
}

export default async function NodePage({ params }: PageProps) {
  const node = await getNode(params.slug);
  if (!node) return notFound();
  return (
    <div>
      <h1>Hello, Next.js! {params.slug}</h1>
      <pre>{JSON.stringify({ node }, null, 2)}</pre>
    </div>
  );
}
...
info  - Compiled successfully
info  - Linting and checking validity of types ...Failed to compile.

Type error: Page "app/[slug]/page.tsx" does not match the required types of a Next.js Page.
  Invalid configuration:
    The exported page component isn't correctly typed.
          Invalid configuration:
            Expected "{ slug: string; } | undefined", got "PageParams | undefined".

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js 13 Upgrade Guide
Learn how to upgrade your Next.js application.
Read more >
What's new in Next.js 13, and what do they really do?
A practical guide to Next.js 13. How real-world code and architecture need to adapt to Server Components, Streaming SSR, Layouts, and Turbopack.
Read more >
nextjs 13 generateStaticParams used with next/header causes ...
When using the function generateStaticParams with the next/header library function headers(),. I get an error in dev mode.
Read more >
Fetching and caching Supabase data in Next.js 13 Server ...
Next.js 13 introduces new data fetching and caching methods to enable React ... For automatically adding types to the Supabase client, ...
Read more >
How to Declare Missing Types for External Libraries -- newline
If DefinitelyTyped doesn't have type declarations for a library you can declare types yourself. Custom Types Declaration#. First, in your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found