Next.js Discord

Discord Forum

Next.js Data Fetching Error => npm run build

Unanswered
MeKa posted this in #help-forum
Open in Discord
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

16 Replies

@MeKa 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
@joulev <https://nextjs-discord-common-questions.joulev.dev/fetching-own-api-endpoint-in-react-server-components>
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
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.
Just like "use server", the same example I did is a situation.
again, use server is not applicable to components, it is simply not relevant
@MeKa Click to see attachment
alright, add
export const dynamic = 'force-dynamic'
to the page
makes sense, I've seen it in the documentation before 😄
@joulev alright, add `export const dynamic = 'force-dynamic'` to the page
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
export const dynamic = 'force-dynamic';
export const revalidate = 1;