config.kit.paths.assets does not support absolute URLs without a scheme
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
The documentation for paths.assets says it requires and "absolute path", but any value not specifying a scheme (e.g. https://, http://) will be rejected with the following error:
config.kit.paths.assets option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths
Any path starting with a / is a valid absolute path, so either the documentation needs updating or the validation check needs to be reworked, here:
My guess is the reason for implementing this feature was to host assets from a CDN which lead to the current validation. However, there are equally valid uses for this setting that would benefit from not having to specify the domain.
In my case, I'm using the static adapter (SPA) with the pages and assets settings defined. I want to serve all static assets from /static/* but the only way to get this to work with the %svelte.assets% variable is to hard code the domain. To avoid this I at least need to hard code the /static value for any of my own static content referenced in app.html. I haven't confirmed this, but I suppose this hard coding approach would not even work with with the built js files which also need access to the assets prefix.
Reproduction
Logs
❯ npm run build
$ svelte-kit build
> config.kit.paths.assets option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths
at eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:632:14)
at eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:798:43)
at eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:784:18)
at eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:784:18)
at eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:784:18)
at validate_config (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:968:9)
at load_config (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:945:20)
at async eval (file:///home/projects/sveltejs-kit-template-default-7pbyt8/node_modules/@sveltejs/kit/dist/cli.js:1080:19)
System Info
System:
OS: Linux 5.16 Arch Linux
CPU: (24) x64 AMD Ryzen Threadripper 1920X 12-Core Processor
Memory: 43.97 GB / 62.71 GB
Container: Yes
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 17.4.0 - /usr/bin/node
npm: 8.5.0 - /usr/bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.17
@sveltejs/adapter-static: ^1.0.0-next.28 => 1.0.0-next.28
@sveltejs/kit: next => 1.0.0-next.278
svelte: ^3.44.0 => 3.46.4
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 in packages/kit/src/core/config/options.js at the validation linked in the report, then reproduce the failure with the linked StackBlitz project and its static adapter configuration. Determine whether slash-prefixed asset paths such as /static should be accepted and whether the paths documentation at the linked URL matches the intended behavior; done means the reported configuration no longer fails unexpectedly or is documented accurately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100