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

Unable to set adapter-static fallback when using bundleStrategy: inline #13233

Open
stephenlrandall opened this issue Dec 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@stephenlrandall
Copy link
Contributor

Describe the bug

Perhaps I'm missing something obvious here, but attempting to use bundleStrategy: inline with adapter-static in a fresh SvelteKit skeleton project produces the following errors:

errors

My configuration is

import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		adapter: adapter({
			pages: 'build',
			assets: 'build',
			fallback: 'index.html'
		}),
		output: {
			bundleStrategy: 'inline'
		}
	}
};

export default config;

Reproduction

Use npx sv create ... and modify the Svelte config file to the above after adding @sveltejs/adapter-static as a dependency.

Logs

[Error] Error: Not found: /Users/.../Desktop/single-page-test/build/index.html
	handleError (index.html:21:4246)
	Me (index.html:19:45323)
	(anonymous function) (index.html:19:42665)
	st (index.html:19:44185)
	ra (index.html:19:34874)
	(anonymous function) (index.html:19:34277)
[Error] Cross origin requests are only supported for HTTP.
	(anonymous function) (index.html:19:28564)
	r (index.html:19:28764)
	(anonymous function) (index.html:19:43111)
[Error] Fetch API cannot load file:///_app/version.json due to access control checks.
	(anonymous function) (index.html:19:28564)
	r (index.html:19:28764)
	(anonymous function) (index.html:19:43111)
[Error] Not allowed to load local resource: file:///favicon.ico

System Info

System:
    OS: macOS 15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 144.17 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.0 - /usr/local/bin/node
    npm: 10.1.0 - /usr/local/bin/npm
    pnpm: 9.15.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.205
    Edge: 131.0.2903.112
    Safari: 18.2
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1 
    @sveltejs/adapter-static: ^3.0.0 => 3.0.8 
    @sveltejs/kit: ^2.0.0 => 2.15.0 
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.4 
    svelte: ^5.0.0 => 5.15.0 
    vite: ^5.4.11 => 5.4.11

Severity

annoyance

Additional Information

Really happy to see this feature getting attention -- it's incredibly useful in certain environments.

@stephenlrandall
Copy link
Contributor Author

If I don't specify a fallback and instead pre-render all pages, it seems to work. Unfortunately, I'm trying to create an SPA -- is this fundamentally incompatible with an inline build?

@stephenlrandall stephenlrandall changed the title Asset request failures with bundleStrategy: inline Unable to set adapter-static fallback when using bundleStrategy: inline Dec 23, 2024
@gterras
Copy link

gterras commented Dec 24, 2024

Static output still needs to be served from http as seen in the error message (so apache/nginx or such).

@eltigerchino eltigerchino added the bug Something isn't working label Dec 24, 2024
@khromov
Copy link

khromov commented Jan 3, 2025

Hey @eltigerchino , I looked into this and I think the issue for you is that when you open the file the route is not / but instead /single-page-test/build/index.html

If you create a catch-all route like src/routes/[...rest]/+page.svelte you will see that it will be invoked. If you want the build to both work on a web server (served from root) and served from index.html, I think you need to get a bit creative with the routing to make sure it works in all cases.

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
Development

No branches or pull requests

4 participants