Axios Interceptors Failing in Server Components During Build Time

I’m having an issue with axios interceptors in Next.js server components. When I try to use axios with interceptors for data fetching in server components during build time, the requests fail. However, using fetch or direct axios calls (without interceptors) works fine.

// This fails during build time
const response = await serverApi.navigation.getFooter(); // Uses axios with interceptors

// This works fine
const response = await fetch(‘/api/navigation/footer’); // Direct fetch

Setup:
Next.js 13 with App Router
Server components using axios interceptors for API calls
Interceptors configured to add headers like cookies, user-agent, etc. using headers() and cookies()

Question:
Is this expected behavior? Should I avoid axios interceptors entirely in server components and stick with direct fetch calls? Or is there a recommended pattern for handling this scenario where I need different behavior for build time vs. request time?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.