next.js: Next 13: Missing Types for generateStaticParams
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:
- https://github.com/vercel/next.js/discussions/41826#discussioncomment-3966869
- https://github.com/vercel/next.js/discussions/41745#discussioncomment-3971314
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 16
- Comments: 22 (2 by maintainers)
Commits related to this issue
- Fix build type error of page params (#42019) This PR temporarily fixes #41884 by loosing the type check rules. I will work on a follow up PR to type params better with tests. ## Bug - [ ] Rela... — committed to vercel/next.js by shuding 2 years ago
- type hack for nextjs build bug https://github.com/vercel/next.js/issues/41884 — committed to gabrielgrover/improved-octo-spoon by gabrielgrover 2 years ago
@thaddeuscleo I have got it now:
params
and if necessarysearchParams
must be declared as optional, then the compiler does not complain anymore.With it also own separately declared props types work.
I’m currently running
"next": "^13.0.3"
and i still facing same issue when executingnpm run build
. this line of code cause the build to fail:This is the error when executing
npm run build
: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…
I’m facing the same problem during build:
@shuding Any news on this? This is preventing me from deploying.
@shuding I still seem to be getting this error. Here is the result of running
next build
Here is the file it is failing at https://github.com/gabrielgrover/improved-octo-spoon/blob/main/app/blog/[slug]/page.tsx
@gabrielgrover We already released
13.0.1
, let us know if the issue is still happening!the perfect fix It worked 😃 thank you
This is still happening for me on Next 13.1.4, only during
next build
:app/[username]/[storySlug]/page.js
Changing it to the following causes the error to not happen:
app/[username]/[storySlug]/page.js
After updating to 13.0.1, I was still facing the issue. However, I fixed it by updating the page’s type from NextPage to FC.