Next.js Discord

Discord Forum

fetch failed on library dependency on next build

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

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