Skip to content

SvelteKit 1.9 and 1.10 using "base" config parameter and static adapter creates wrong imports (falsely prependended by ".").  #9341

@mdi22

Description

@mdi22

Describe the bug

Using the static adapter (sveltejs/adapter-static), Sveltekit builds wrong links in the created HTML files.
The "base" parameter ist set to "build" so that the application is found in a sub-path "/build".
See "base" parameter under https://kit.svelte.dev/docs/configuration#paths

In sveltejs/kit Version 1.8.8 a typical link in a created index.html looks like that:

<link rel="modulepreload" href="/build/_app/immutable/entry/start.84521e90.js">

In sveltejs/kit Version 1.10.0 and 1.9.0 it looks like that:

<link rel="modulepreload" href="./build/_app/immutable/entry/start.84521e90.js">

A dot (".") is prepended the created href, leading to a wrong path:
when accessing "http://localhost/build/index.html", the dot leads to a path reference to "http://localhost/build/build/_app/immutable/entry/start.84521e90.js"

It seems this behavior makes the "base" parameter obsolete, as the sveltekit app is always accessible in any sub directory without any further need of configuration, because no absolute paths are used anymore.

That new behaviour is great!
But only if the base parameter is not set, otherwise the site is broken.

Still, in the documentation
https://kit.svelte.dev/docs/configuration#paths
there is written to use the "base" parameter in the case of non-root-paths.

If I understand everything right, the solution can simply be to update the documentation, that no base parameter is needed anymore (remove it from documentation).
Also, an existing base parameter must be ignored and marked deprecated, or lead to an error with the message, that this parameter is not available/allowed anymore.

Reproduction

I am using sveltejs/kit 1.9.0 or 1.10.0 and sveltejs/adapter-static 2.0.1

The vite config is:

import { sveltekit } from '@sveltejs/kit/vite'

const config = {
	plugins: [sveltekit(),],
	server: {
		port: 3000,
		fs: {
			// Allow serving files from one level up to the project root
			allow: ['..']
		},
		base: "/build"
	},
	preview: {
		port: 3000
	},
	test: {
		globals: true
	}
}
export default config

The Svelte configuration is:

import adapter_static from '@sveltejs/adapter-static'
import preprocess from 'svelte-preprocess'

const config = {
	preprocess: preprocess(),
	onwarn(warning, defaultHandler) {
		defaultHandler(warning)
	},
	kit: {
		adapter: adapter_static(),
		paths: {
			base: "/build"
		}
	}
}
export default config

Logs

No response

System Info

System:
    OS: Linux 6.1 Ubuntu 22.10 22.10 (Kinetic Kudu)
    CPU: (16) x64 AMD Ryzen 7 6800U with Radeon Graphics
    Memory: 2.17 GB / 13.33 GB
    Container: Yes
    Shell: 5.2.2 - /bin/bash
  Binaries:
    Node: 19.7.0 - /usr/bin/node
    npm: 9.5.0 - /usr/bin/npm
  Browsers:
    Chrome: 110.0.5481.177
    Firefox: 110.0.1
  npmPackages:
    @sveltejs/adapter-auto: ^2.0 => 2.0.0 
    @sveltejs/adapter-node: ^1.2 => 1.2.1 
    @sveltejs/adapter-static: ^2.0 => 2.0.1 
    @sveltejs/kit: 1.9.0 => 1.9.0 
    svelte: ^3.55 => 3.55.1

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions