base path / trailing slash with loading assets from incorrect path
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
Due to base path not being configurable via environment variables(after build)(related: #7242), when using adapters such as adapter-node, and you don't want to build a version of your app for every possible base path.
You can currently get around this by setting
config.kit.paths.base: ""
while also setting export const trailingSlash = 'always'; in a top level +layout.server.ts
This makes it so assets gets loaded from the correct path, https://example.com/somepath/_app/... instead of https://example.com/_app/...
But this also results in #13718, which you can work around by setting either of the following environment variables ORIGIN="https://example.com/somepath" or HOST_HEADER=x-forwarded-host.
This fixes redirects done by sveltekit from non trailing slash to trailing slash when export const trailingSlash = 'always'; is set, but this also effectively undoes the fixes for to the assets paths which means they are returned to being https://example.com/_app/... instead of https://example.com/somepath/_app/...
And the only actual work around for us at the moment is building our app around 30 times to account for all the different base paths instead of once and then just having to set an environment variable
Reproduction
minimal repro using the demo app, with readme explaining setup
Logs
System Info
System:
OS: Linux 6.17 Garuda Linux
CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
Memory: 30.78 GB / 62.70 GB
Container: Yes
Shell: 4.2.1 - /usr/bin/fish
Binaries:
Node: 24.12.0 - /run/user/1000/fnm_multishells/3392617_1765799124583/bin/node
npm: 11.6.2 - /run/user/1000/fnm_multishells/3392617_1765799124583/bin/npm
pnpm: 10.7.0 - /home/$USER/.npm-global/bin/pnpm
bun: 1.3.4 - /home/$USER/.bun/bin/bun
Deno: 2.5.6 - /usr/bin/deno
Browsers:
Chromium: 143.0.7499.109
Firefox: 146.0
Firefox Developer Edition: 146.0
npmPackages:
@sveltejs/adapter-node: ^5.4.0 => 5.4.0
@sveltejs/kit: ^2.49.2 => 2.49.2
@sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1
svelte: ^5.46.0 => 5.46.0
vite: ^7.3.0 => 7.3.0
Severity
annoyance
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked minimal reproduction and compare asset URLs and redirects with config.kit.paths.base, trailingSlash, ORIGIN, and HOST_HEADER set as described. Trace how adapter-node determines the base path after build; done means assets use the deployed base path while trailing-slash redirects remain correct without rebuilding for each path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100