Path in `svelte.config.js` is not always respected, leading to it breaking
Describe the bug
When changing the base path in svelte.config.js, neither npm run preview nor the actual files work anymore, as they reference the paths without any additional names. I've searched this up a lot and couldn't find anything or what I might be doing wrong, so I assume it's a bug? I am not sure though.
It is probably fixable by manually going in and changing the paths, but that should not be required.
Reproduction
https://github.com/mybearworld/svelte-base-path-bug-report
- Make a new Svelte app with Typescript using
npm create svelte@latest svelte-base-path-bug-report - Install dependencies with
npm i - Install static adapter with
npm i @sveltejs/adapter-static - Change
svelte.config.jsto the file below - Create
/src/routes/+layout.tsasexport const prerender = true; export const ssr = false; - Build with
npm run build - See it fail, while working perfectly fine without config.paths
import adapter from "@sveltejs/adapter-static";
const dev = process.argv.includes("dev");
const config = {
kit: {
adapter: adapter({
pages: "build",
assets: "build",
fallback: undefined,
precompress: false,
strict: true,
}),
paths: {
base: dev ? "" : "/svelte-base-path-bug-report",
},
},
};
export default config;
Logs
Failed to load resource: the server responded with a status of 404 (Not Found) start.479a71cd.js:1
Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: http://localhost:4173/_app/immutable/entry/start.479a71cd.js svelte-base-path-bug-report:1
Failed to load resource: the server responded with a status of 404 (Not Found) singletons.8af3bb0e.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) app.71e45c29.js:1
System Info
System:
OS: Windows 10 10.0.22621
CPU: (2) x64 AMD Athlon Silver 3050U with Radeon Graphics
Memory: 713.66 MB / 5.94 GB
Binaries:
Node: 18.16.0 - ~\Appdata\Local\NodeJs\node.EXE
Yarn: 3.5.1 - ~\Appdata\Local\NodeJs\yarn.CMD
npm: 9.6.6 - ~\Appdata\Local\NodeJs\npm.CMD
Browsers:
Edge: Spartan (44.22621.1702.0), Chromium (113.0.1774.42), ChromiumDev (111.0.1660.12)
Internet Explorer: 11.0.22621.1
npmPackages:
svelte: ^3.54.0 => 3.59.1
Severity
annoyance
This worked in 1.15.5, and was broken in 1.15.6 by #9343
- Clone
https://github.com/mybearworld/svelte-base-path-bug-report npm inpm run buildnpm run preview- Load:
http://127.0.0.1:4173/svelte-base-path-bug-reportand see that it fails. Going tohttp://127.0.0.1:4173/svelte-base-path-bug-report/(trailing slash) works, SvelteKit is using client-side logic to silently remove the slash, so if you refresh, you're back at no-slash not-working.
Now, do:
npm i @sveltejs/[email protected]npm run buildnpm run preview- Load:
http://127.0.0.1:4173/svelte-base-path-bug-reportwhich now works. But nowhttp://127.0.0.1:4173/svelte-base-path-bug-report/(trailing slash) is broken.
@Rich-Harris will probably need to chime in as he was behind #9343... but I imagine that the preview server just needs to redirect /your-base to /your-base/ and whatever client-side code is stripping the slashes off the end needs to refrain from doing that for the base URL.
This worked in 1.15.5, and was broken in 1.15.6 by #9343
- Clone
https://github.com/mybearworld/svelte-base-path-bug-reportnpm inpm run buildnpm run preview- Load:
http://127.0.0.1:4173/svelte-base-path-bug-reportand see that it fails. Going tohttp://127.0.0.1:4173/svelte-base-path-bug-report/(trailing slash) works, SvelteKit is using client-side logic to silently remove the slash, so if you refresh, you're back at no-slash not-working.Now, do:
npm i @sveltejs/[email protected]npm run buildnpm run preview- Load:
http://127.0.0.1:4173/svelte-base-path-bug-reportwhich now works. But nowhttp://127.0.0.1:4173/svelte-base-path-bug-report/(trailing slash) is broken.@Rich-Harris will probably need to chime in as he was behind #9343... but I imagine that the preview server just needs to redirect
/your-baseto/your-base/and whatever client-side code is stripping the slashes off the end needs to refrain from doing that for the base URL.
I confirm. Last working version when a base is set : 1.15.5, above nothing else work
I can't seem to reproduce this. The build works when I try it in stackblitz. Can you confirm if it still broken on your end?
@s3812497 I can still reproduce it. I used my instructions in this comment but first ran npm i @sveltejs/kit to get SvelteKit version 1.25.0.
The issue persists.