Errors in Next.js Production Build #330

Closed
opened 2026-03-13 07:42:00 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @aleksa-codes on GitHub (Dec 3, 2024).

First off, props for this project, it's been an amazing experience and incredibly easy to use, especially coming from Supabase Auth. Truly appreciate the effort.

Describe the bug
Everything works perfectly in development mode. However, after building the Next.js 15 project, the following error occurs:

TypeError: fetch failed
    at async P (D:\Projects\nextjs-starterkit\.next\server\chunks\56.js:3:111320)
    at async (D:\Projects\nextjs-starterkit\.next\server\chunks\56.js:3:108459) {
  [cause]: [AggregateError: ] { code: 'ECONNREFUSED' }
}

To Reproduce
Steps to reproduce the behavior:

  1. Clone this repository: nextjs-starterkit-better-auth

  2. Build the project using next build or yarn build

  3. Observe the fetch error.

Expected behavior
No errors should occur during the build.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Microsoft Edge
  • Node.js Version: v20.16.0

Smartphone (please complete the following information):
N/A

Additional context

Please let me know if further details are required!

Originally created by @aleksa-codes on GitHub (Dec 3, 2024). First off, props for this project, it's been an amazing experience and incredibly easy to use, especially coming from Supabase Auth. Truly appreciate the effort. **Describe the bug** Everything works perfectly in development mode. However, after building the Next.js 15 project, the following error occurs: ```plaintext TypeError: fetch failed at async P (D:\Projects\nextjs-starterkit\.next\server\chunks\56.js:3:111320) at async (D:\Projects\nextjs-starterkit\.next\server\chunks\56.js:3:108459) { [cause]: [AggregateError: ] { code: 'ECONNREFUSED' } } ``` **To Reproduce** Steps to reproduce the behavior: 1. Clone this repository: [nextjs-starterkit-better-auth](https://github.com/aleksa-codes/nextjs-starterkit-better-auth) 2. Build the project using `next build` or `yarn build` 3. Observe the fetch error. **Expected behavior** No errors should occur during the build. **Screenshots** N/A **Desktop (please complete the following information):** - OS: Windows 11 - Browser: Microsoft Edge - Node.js Version: v20.16.0 **Smartphone (please complete the following information):** N/A **Additional context** - Framework: Next.js 15 - Issue observed in this repository: [nextjs-starterkit-better-auth](https://github.com/aleksa-codes/nextjs-starterkit-better-auth) Please let me know if further details are required!
Author
Owner

@LexiconAlex commented on GitHub (Dec 3, 2024):

// Don't hardcode URLs like this
fetch('http://localhost:3000/api/...')

// Instead, use environment variables or relative URLs
fetch('/api/...')
// or
fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`)
@LexiconAlex commented on GitHub (Dec 3, 2024): ``` // Don't hardcode URLs like this fetch('http://localhost:3000/api/...') // Instead, use environment variables or relative URLs fetch('/api/...') // or fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`) ```
Author
Owner

@aleksa-codes commented on GitHub (Dec 3, 2024):

// Don't hardcode URLs like this
fetch('http://localhost:3000/api/...')

// Instead, use environment variables or relative URLs
fetch('/api/...')
// or
fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`)

I checked and none of my fetch requests have hardcoded URLs like:

fetch('http://localhost:3000/api/...')

I am using relative everywhere, but also gave this a shot:

fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`)

still no luck.

@aleksa-codes commented on GitHub (Dec 3, 2024): > ``` > // Don't hardcode URLs like this > fetch('http://localhost:3000/api/...') > > // Instead, use environment variables or relative URLs > fetch('/api/...') > // or > fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`) > ``` I checked and none of my fetch requests have hardcoded URLs like: ``` fetch('http://localhost:3000/api/...') ``` I am using relative everywhere, but also gave this a shot: ``` fetch(`${process.env.NEXT_PUBLIC_API_URL}/...`) ``` still no luck.
Author
Owner

@LexiconAlex commented on GitHub (Dec 3, 2024):

It might be easier if you share your code.

@LexiconAlex commented on GitHub (Dec 3, 2024): It might be easier if you share your code.
Author
Owner

@aleksa-codes commented on GitHub (Dec 4, 2024):

It might be easier if you share your code.

Thank you for the suggestion. I assumed the code had already been reviewed since there was a mention of hardcoded URL values in the fetch requests. The repository is linked within the issue text, but for convenience, here are the steps to reproduce:

  1. git clone https://github.com/aleksa-codes/nextjs-starterkit-better-auth.git (or fork then clone)
  2. cd nextjs-starterkit-better-auth
  3. Rename .env.example to .env.
  4. Generate a BETTER_AUTH_SECRET at https://www.better-auth.com/docs/installation#set-environment-variables and set it in the .env file.
  5. Run yarn install or npm install.
  6. Run yarn build or npm run build.

I tried sharing a StackBlitz link but was not able to get the project to work there. Please let me know if there’s anything else I can clarify or assist with.

@aleksa-codes commented on GitHub (Dec 4, 2024): > It might be easier if you share your code. Thank you for the suggestion. I assumed the code had already been reviewed since there was a mention of hardcoded URL values in the fetch requests. The repository is linked within the issue text, but for convenience, here are the steps to reproduce: 1. `git clone https://github.com/aleksa-codes/nextjs-starterkit-better-auth.git` (or fork then clone) 2. `cd nextjs-starterkit-better-auth` 3. Rename `.env.example` to `.env`. 4. Generate a `BETTER_AUTH_SECRET` at [https://www.better-auth.com/docs/installation#set-environment-variables](https://www.better-auth.com/docs/installation#set-environment-variables) and set it in the `.env` file. 5. Run `yarn install` or `npm install`. 6. Run `yarn build` or `npm run build`. I tried sharing a StackBlitz link but was not able to get the project to work there. Please let me know if there’s anything else I can clarify or assist with.
Author
Owner

@aleksa-codes commented on GitHub (Dec 6, 2024):

Even with the code attached I am getting no help, also seen this bug/issue reported on discord multiple times but the problem was also dodged in similar fashion. Seems to be maybe duplicate of https://github.com/better-auth/better-auth/issues/480 so closing it.

@aleksa-codes commented on GitHub (Dec 6, 2024): Even with the code attached I am getting no help, also seen this bug/issue reported on discord multiple times but the problem was also dodged in similar fashion. Seems to be maybe duplicate of https://github.com/better-auth/better-auth/issues/480 so closing it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#330