SIGN IN SIGN UP
payloadcms / payload UNCLAIMED

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

0 0 281 TypeScript

fix: set basePath from next config as env variable (#15154)

### What
Fix image preview URLs not displaying when `basePath` is set in
`next.config.mjs`.

### Why
When `basePath` is set in `next.config.mjs`, the `withPayload` function
assigns it as an env variable. However, currently the file sets
`basePath` as `baseConfig.env.NEXT_BASE_PATH`, which is only accessible
in Next.js runtime contexts (API routes, server components).

Upload URLs are generated from `formatAdminURL` in the Node.js
environment, where `baseConfig.env.NEXT_BASE_PATH` cannot be accessed.
As a result, it thinks no `basePath` is set and uses the incorrect URL
to render the upload preview.

### Where
`withPayload` now sets both `baseConfig.env.NEXT_BASE_PATH` **and**
`process.env.NEXT_BASE_PATH`, making `basePath` available everywhere.

Previously, users had to manually set `NEXT_BASE_PATH` in `.env` to work
around this.

##### Fixes #15111
J
Jessica Rynkar committed
a8bfade1e13285611bb947f0285deff94aa16084
Parent: 88a901c
Committed by GitHub <noreply@github.com> on 1/13/2026, 5:12:01 PM