Nextbase Docs
Known Issues

Build Error with Undici

How to resolve the build error related to Undici when using localhost URLs in production environments.

Build Error with Undici

You may encounter a build error related to Undici when trying to deploy your Next.js application to a production environment. This issue typically occurs when using localhost URLs in your production configuration.

The Problem

The error message might look something like this:

error validating user TypeError: fetch failed
at Object.fetch (/var/task/node_modules/next/dist/compiled/undici/index.js:1:26684)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async validateUser (/var/task/.next/server/app/page.js:740:21)
at async HomePage (/var/task/.next/server/app/page.js:674:17) {
cause: TypeError: Cannot read properties of undefined (reading 'reason')
at makeAppropriateNetworkError (/var/task/node_modules/next/dist/compiled/undici/index.js:2:54604)
at schemeFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:30000)
at /var/task/node_modules/next/dist/compiled/undici/index.js:2:28607
at mainFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:29007)
at httpRedirectFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:33708)
at httpFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:32580)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async schemeFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:30793)
at async /var/task/node_modules/next/dist/compiled/undici/index.js:2:28601
at async mainFetch (/var/task/node_modules/next/dist/compiled/undici/index.js:2:28426)

References

This issue on the next.js GitHub repository talks about it:

Fix

To fix the issue, you need to ensure that the build environment doesn't have environment variables that point to localhost. If they are, you need to change them to 127.0.0.1.

On this page