Cannot build NextJS app router without errors #85

Closed
opened 2026-03-13 07:32:27 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @proevilz on GitHub (Oct 16, 2024).

Describe the bug
If you use useSession() in a client component and then attempt to npm run build, it appears to try and execute a rogue fetch() request and errors out, since it obviously can't complete the request since there is no server at build time.

To Reproduce
Steps to reproduce the behavior:

  1. Go to clone the test repo: https://github.com/proevilz/better-auth-test
  2. run npm i && npm run build

Expected behavior
Build completes without errors

Screenshots
image

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Irrelevant
  • Version: Irrelevant

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

^ all irrelevant

Additional context
Add any other context about the problem here.

Originally created by @proevilz on GitHub (Oct 16, 2024). **Describe the bug** If you use `useSession()` in a client component and then attempt to `npm run build`, it appears to try and execute a rogue `fetch()` request and errors out, since it obviously can't complete the request since there is no server at build time. **To Reproduce** Steps to reproduce the behavior: 1. Go to clone the test repo: https://github.com/proevilz/better-auth-test 2. run `npm i && npm run build` **Expected behavior** Build completes without errors **Screenshots** ![image](https://github.com/user-attachments/assets/c5651a79-071d-4ee5-9912-cdf164c94a82) **Desktop (please complete the following information):** - OS: MacOS - Browser: Irrelevant - Version: Irrelevant **Smartphone (please complete the following information):** - Device: [e.g. iPhone6] - OS: [e.g. iOS8.1] - Browser [e.g. stock browser, safari] - Version [e.g. 22] ^ all irrelevant **Additional context** Add any other context about the problem here.
Author
Owner

@Bekacru commented on GitHub (Nov 1, 2024):

This is due to having useSession being called on a statically rendered path. Make sure the route is dynamic so next won't try to fetch a session on build.

@Bekacru commented on GitHub (Nov 1, 2024): This is due to having `useSession` being called on a statically rendered path. Make sure the route is dynamic so next won't try to fetch a session on build.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#85