Problem with generateMetadata()
Unanswered
Japanese common catfish posted this in #help-forum
Japanese common catfishOP
This is my StoreLayout (which is not the root layout, and there is another layout function over this one that's exporting a metadata object).
This works in Dev, but in production... it creates this error:
export async function generateMetadata(): Promise<Metadata> {
const requestHeaders = headers();
const subdomain = (requestHeaders.get('host') || 'localhost:3000').split('.').slice(0, isProduction ? -2 : -1).join('.');
const result = await getSchoolByStoreURL(subdomain);
return {
title: (result ? result?.name + ' - ' : '') + 'Nineteen Production',
description: '',
}
}
export default function StoreLayout ({ children }: RootLayoutProps) {
return (
<div className="pt-[105px]">
{children}
</div>
)
}This works in Dev, but in production... it creates this error:
.next/types/app/page.ts:32:15
Type error: Type 'OmitWithTag<ResolvingMetadata, keyof PageProps, "generateMetadata">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'then' is incompatible with index signature.
Type '<TResult1 = ResolvedMetadata, TResult2 = never>(onfulfilled?: ((value: ResolvedMetadata) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise<...>' is not assignable to type 'never'.
30 | // Check the arguments and return type of the generateMetadata function
31 | if ('generateMetadata' in entry) {
> 32 | checkFields<Diff<PageProps, FirstArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
| ^
33 | checkFields<Diff<ResolvingMetadata, SecondArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
34 | }
35 |1 Reply
@Japanese common catfish This is my StoreLayout (which is not the root layout, and there is another layout function over this one that's exporting a metadata object).
export async function generateMetadata(): Promise<Metadata> {
const requestHeaders = headers();
const subdomain = (requestHeaders.get('host') || 'localhost:3000').split('.').slice(0, isProduction ? -2 : -1).join('.');
const result = await getSchoolByStoreURL(subdomain);
return {
title: (result ? result?.name + ' - ' : '') + 'Nineteen Production',
description: '',
}
}
export default function StoreLayout ({ children }: RootLayoutProps) {
return (
<div className="pt-[105px]">
{children}
</div>
)
}
This works in Dev, but in production... it creates this error:
.next/types/app/page.ts:32:15
Type error: Type 'OmitWithTag<ResolvingMetadata, keyof PageProps, "generateMetadata">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'then' is incompatible with index signature.
Type '<TResult1 = ResolvedMetadata, TResult2 = never>(onfulfilled?: ((value: ResolvedMetadata) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise<...>' is not assignable to type 'never'.
30 | // Check the arguments and return type of the generateMetadata function
31 | if ('generateMetadata' in entry) {
> 32 | checkFields<Diff<PageProps, FirstArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
| ^
33 | checkFields<Diff<ResolvingMetadata, SecondArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
34 | }
35 |
export async function generateMetadata(): Promise<Metadata> {
//const requestHeaders = headers();
//const subdomain = (requestHeaders.get('host') || 'localhost:3000').split('.').slice(0, isProduction ? -2 : -1).join('.');
//const result = await getSchoolByStoreURL(subdomain);
return {
title: 'Nineteen Production',
description: '',
}
}hi, does it work if you comment out these line