fetch failed on library dependency on next build
Unanswered
Fire ant posted this in #help-forum
Fire antOP
I create my API using some npm package(node library) to get the json data, using app route.
My api url like http://localhost:4444/
In dev mode, everything is working, when building its failed to fetch.
I need to implement new nodejs backend API to make it work when building it.
How do i make it work without implementing new node backend API outside from Nextjs dir? Like no need to make new nodejs backend to act as API
My api url like http://localhost:4444/
const api = process.env.API_URL // using .env
const data = await fetch(`${api}/api/list`); // app route api
const res = await data.json();
In dev mode, everything is working, when building its failed to fetch.
I need to implement new nodejs backend API to make it work when building it.
How do i make it work without implementing new node backend API outside from Nextjs dir? Like no need to make new nodejs backend to act as API
3 Replies
@Fire ant I create my API using some npm package(node library) to get the json data, using app route.
My api url like http://localhost:4444/
js
const api = process.env.API_URL // using .env
const data = await fetch(`${api}/api/list`); // app route api
const res = await data.json();
In dev mode, everything is working, when building its failed to fetch.
I need to implement new nodejs backend API to make it work when building it.
How do i make it work without implementing new node backend API outside from Nextjs dir? Like no need to make new nodejs backend to act as API
you should just fetch/get the json data directly in the server component
you don't need to create a route handler for rendering the page