kit icon indicating copy to clipboard operation
kit copied to clipboard

Path in `svelte.config.js` is not always respected, leading to it breaking

Open mybearworld opened this issue 1 year ago • 1 comments

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.js to the file below
  • Create /src/routes/+layout.ts as export 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

mybearworld avatar May 18 '23 16:05 mybearworld

This worked in 1.15.5, and was broken in 1.15.6 by #9343

  1. Clone https://github.com/mybearworld/svelte-base-path-bug-report
  2. npm i
  3. npm run build
  4. npm run preview
  5. Load: http://127.0.0.1:4173/svelte-base-path-bug-report and see that it fails. Going to http://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:

  1. npm i @sveltejs/[email protected]
  2. npm run build
  3. npm run preview
  4. Load: http://127.0.0.1:4173/svelte-base-path-bug-report which now works. But now http://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.

markjaquith avatar May 21 '23 08:05 markjaquith

This worked in 1.15.5, and was broken in 1.15.6 by #9343

  1. Clone https://github.com/mybearworld/svelte-base-path-bug-report
  2. npm i
  3. npm run build
  4. npm run preview
  5. Load: http://127.0.0.1:4173/svelte-base-path-bug-report and see that it fails. Going to http://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:

  1. npm i @sveltejs/[email protected]
  2. npm run build
  3. npm run preview
  4. Load: http://127.0.0.1:4173/svelte-base-path-bug-report which now works. But now http://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.

I confirm. Last working version when a base is set : 1.15.5, above nothing else work

julien-vu avatar Jul 11 '23 12:07 julien-vu

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?

eltigerchino avatar Sep 20 '23 23:09 eltigerchino

@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.

markjaquith avatar Sep 21 '23 00:09 markjaquith