Next.js Discord

Discord Forum

problem build

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Type error: Type 'OmitWithTag<typeof import("C:/Users/NanoDev/Documents/ecommerce-website-nextjs14-approuter/src/app/[product]/[id]/page"), "metadata" | "default" | "config" | "generateStaticParams" | ... 9 more ... | "generateViewport", "">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'getProduct' is incompatible with index signature.
Type '(id: string) => Promise<ProductData>' is not assignable to type 'never'.

6 |
7 | // Check that the entry is a valid entry
8 | checkFields<Diff<{
| ^
9 | default: Function
10 | config?: {}
11 | generateStaticParams?: Function
Answered by joulev
You cannot export getProduct from a page file. If you want to use the getProduct function elsewhere, move it to its own file. If you don’t need to use the function anywhere else, remove the export keyword
View full answer

7 Replies

Answer
after this
Generating static pages (33/40) [ ==]q [Error]: Dynamic server usage: Route /api/search couldn't be rendered statically because it used request.url. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
at W (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:21106)
at Object.get (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:28459)
at c (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter.next\server\app\api\search\route.js:1:656)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:36258
at async eR.execute (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:26874)
at async eR.handle (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:37512)
at async exportAppRoute (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\export\routes\app-route.js:77:26)
at async exportPageImpl (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\export\worker.js:175:20)
at async Span.traceAsyncFn (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\trace\trace.js:154:20) {
description: "Route /api/search couldn't be rendered statically because it used request.url. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
digest: 'DYNAMIC_SERVER_USAGE'
}
@joulev You cannot export getProduct from a page file. If you want to use the getProduct function elsewhere, move it to its own file. If you don’t need to use the function anywhere else, remove the export keyword
Cape lionOP
"use server"
import { ICategory } from '@/models/Category';

interface ProductData {
_id: string;
name: string;
description: string;
ref: string;
price: number;
imageUrl?: string;
brand: brand;
stock: number;
discount?: number;
color?: string;
material?: string;
status?: string;
}

interface brand {
_id: string;
name: string;
}

// Function to fetch category data by ID
export async function fetchCategoryData(id: string): Promise<ICategory | null> {
try {
const res = await fetch(${process.env.NEXTAUTH_URL}/api/searchcategory?category=${id});
if (!res.ok) {
throw new Error('Category not found');
}
const data: ICategory = await res.json();
return data;
} catch (error) {
console.error('Error fetching category data:', error);
return null;
}
}

// Function to fetch products data by category ID
export async function fetchProductsData(id: string): Promise<ProductData[]> {
try {
const res = await fetch(${process.env.NEXTAUTH_URL}/api/search?category=${id});
if (!res.ok) {
throw new Error('Products not found');
}
const data: ProductData[] = await res.json();
return data;
} catch (error) {
console.error('Error fetching products data:', error);
return [];
}
}

// Function to fetch brand data
export async function fetchBrandData(): Promise<brand[]> {
try {
const res = await fetch(${process.env.NEXTAUTH_URL}/api/brand/getAllBrand);
if (!res.ok) {
throw new Error('Brand not found');
}
const data: brand[] = await res.json();
return data;
} catch (error) {
console.error('Error fetching brand data:', error);
return [];
}
}
@Cape lion Generating static pages (33/40) [ ==]q [Error]: Dynamic server usage: Route /api/search couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error at W (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:21106) at Object.get (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:28459) at c (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\.next\server\app\api\search\route.js:1:656) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:36258 at async eR.execute (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:26874) at async eR.handle (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:37512) at async exportAppRoute (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\export\routes\app-route.js:77:26) at async exportPageImpl (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\export\worker.js:175:20) at async Span.traceAsyncFn (C:\Users\NanoDev\Documents\ecommerce-website-nextjs14-approuter\node_modules\next\dist\trace\trace.js:154:20) { description: "Route /api/search couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error", digest: 'DYNAMIC_SERVER_USAGE' }
That’s a different error, please open a new post
Cape lionOP
ok