Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mybearworld opened this issue May 18, 2023 · 4 comments · Fixed by #10763
Closed

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

mybearworld opened this issue May 18, 2023 · 4 comments · Fixed by #10763
Labels
bug Something isn't working

Comments

@mybearworld
Copy link

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

@gtm-nayan gtm-nayan transferred this issue from sveltejs/svelte May 19, 2023
@markjaquith
Copy link
Contributor

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.

@julien-vu
Copy link

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

@eltigerchino
Copy link
Member

eltigerchino commented Sep 20, 2023

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?

@markjaquith
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants