Next.js Data Fetching Error => npm run build
Unanswered
MeKa posted this in #help-forum
MeKaOP
I'm getting these errors when running the "npm run build" command.
api path is a working api in this project
locahost:3000/api/example
api path is a working api in this project
locahost:3000/api/example
16 Replies
@joulev <https://nextjs-discord-common-questions.joulev.dev/fetching-own-api-endpoint-in-react-server-components>
MeKaOP
Is this just because I'm calling my own api path? because I tried the "use server" method. It brought it successfully, but the data I just added did not come.
"use server" is only applicable to server actions, it is not applicable to components
as for why the fetch failed, it is because your api is not running during build, just read the link
@joulev "use server" is only applicable to server actions, it is not applicable to components
MeKaOP
import { prisma } from "~/lib/prisma";
export default async function Page() {
const user = await prisma.user.findUnique({ where: { id: 123456 } });
return <div>{user?.name}</div>;
}
I made all the pages in this style. After I got "npm run build" I started it with "npm start" command. Later, I added a new user from the panel and although I did it like the example there, the added data did not come to the Users List.
export default async function Page() {
const user = await prisma.user.findUnique({ where: { id: 123456 } });
return <div>{user?.name}</div>;
}
I made all the pages in this style. After I got "npm run build" I started it with "npm start" command. Later, I added a new user from the panel and although I did it like the example there, the added data did not come to the Users List.
@MeKa import { prisma } from "~/lib/prisma";
export default async function Page() {
const user = await prisma.user.findUnique({ where: { id: 123456 } });
return <div>{user?.name}</div>;
}
I made all the pages in this style. After I got "npm run build" I started it with "npm start" command. Later, I added a new user from the panel and although I did it like the example there, the added data did not come to the Users List.
that is because your page was rendered statically; if you want to update it you have two choices:
* use dynamic rendering for it https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering
* and/or use on-demand revalidation where you revalidate the page of interest using
* use dynamic rendering for it https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering
* and/or use on-demand revalidation where you revalidate the page of interest using
revalidatePath https://nextjs.org/docs/app/building-your-application/data-fetching/revalidatingMeKaOP
Just like "use server", the same example I did is a situation.
again,
use server is not applicable to components, it is simply not relevantMeKaOP
@MeKa Click to see attachment
alright, add
to the page
export const dynamic = 'force-dynamic'to the page
@joulev that is because your page was rendered statically; if you want to update it you have two choices:
* use dynamic rendering for it <https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic-rendering>
* and/or use on-demand revalidation where you revalidate the page of interest using `revalidatePath` <https://nextjs.org/docs/app/building-your-application/data-fetching/revalidating>
if you want to see why, read at least the first link here
MeKaOP
makes sense, I've seen it in the documentation before 😄
@joulev alright, add
`export const dynamic = 'force-dynamic'`
to the page
MeKaOP
Now it's a bit more like I wanted, but I want to learn one more thing. Like Revalidate. After adding a user on the admin panel Add New User page, if the operation is true, I redirect directly to the User List page. but the new member I added there hasn't arrived yet. until I refresh the page and how can I get around this problem?
i dont understand your question but the two links i provided should give you the relevant information
MeKaOP
export const dynamic = 'force-dynamic';
export const revalidate = 1;
export const revalidate = 1;