Repository navigation
fix(desktop): detect SvelteKit adapter-node and error on unsupported adapters - #35533
Conversation
β¦adapters A default SvelteKit app created with `sv create` uses `@sveltejs/adapter-auto`, which framework detection didn't recognize, so it fell through to the generic Vite branch and bundled a non-existent `dist/` directory. Now a `svelte.config.*` makes SvelteKit own detection (no Vite fall-through), `@sveltejs/adapter-node` is recognized (it runs under Deno via Node.js compat, so no Deno-specific adapter is required), and an unsupported/undetermined adapter produces an actionable error instead of a confusing Vite mis-detection.
ReviewThe diagnosis is correct and the fix targets the actual root cause β gating Vite behind One issue worth addressing before merge: Config-extension mismatch now produces a misleading hard errorThe entry gate accepts five extensions: // has_config_file
["js", "mjs", "ts", "mts", "cjs"]but ["svelte.config.js", "svelte.config.ts", "svelte.config.mjs"]
.iter()
.find_map(|f| std::fs::read_to_string(dir.join(f)).ok())
.unwrap_or_default();So a project with This mismatch pre-existed, but the old code returned Minor
Tests are good β replacing the old "unknown adapter β None" test was the right call since that behavior was the bug. Otherwise approve-worthy. |
β¦gate Address review on denoland#35533: the config-presence gate accepted five extensions (js/mjs/ts/mts/cjs) but the SvelteKit config-text read only tried three (js/ts/mjs). A project with svelte.config.mts/.cjs passed the gate, read an empty string, matched no adapter, and bailed with a misleading 'no supported adapter' error even for a valid adapter-node config. Factor the extension list into CONFIG_EXTENSIONS shared by has_config_file and a new read_config_text helper so the two can't drift. Generalize the bail hint to 'your svelte.config' instead of hardcoding svelte.config.js.
A bare svelte.config.* is not SvelteKit-exclusive: the Vite Svelte template ships a svelte.config.js with only vitePreprocess() and no @sveltejs/kit. Gating SvelteKit detection on a config file alone made such plain Svelte SPAs hit detect_sveltekit, match no adapter, and bail instead of falling through to the Vite branch that bundles dist/. Require positive SvelteKit evidence (@sveltejs/kit dependency) before SvelteKit owns detection; otherwise fall through to Vite as before.
|
We can address it in a follow up though |
|
This currently doesn't work with newly initialised sveltekit projects as Output of using
import adapter from '@sveltejs/adapter-node';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
sveltekit({
compilerOptions: {
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
runes: ({ filename }) =>
filename.split(/[/\\]/).includes('node_modules') ? undefined : true,
experimental: { async: true }
},
adapter: adapter(),
experimental: { remoteFunctions: true, handleRenderingErrors: true }
})
]
});Running |
workaround: adapter: adapter({ out: "dist" }) |
Fixes #35531.
Problem
A default SvelteKit app created with
deno run -A npm:sv create my-appuses@sveltejs/adapter-auto, which framework detection didn't recognize. Because SvelteKit ships avite.configand avitedependency, detection fell through to the generic Vite branch ("Detected Vite framework") and tried to bundle a non-existentdist/directory β producing the errors in the issue (No such file or directoryfordist, and the spurious TS5095/TS5109 type-check errors from the Vite SPA entrypoint graph).Fix
In
cli/tools/framework.rs:svelte.config.*now makes SvelteKit own detection. It can no longer fall through to the generic Vite branch, which was the root cause of the misdetection.@sveltejs/adapter-nodeis now recognized. It emits the samebuild/index.jsserver shape assvelte-adapter-denoand runs under Deno via Node.js compatibility, so no Deno-specific adapter is required.adapter-auto(thesv createdefault), which produces no local server output at all.Tests
detects_sveltekit_adapter_node_from_configerrors_on_sveltekit_adapter_autoerrors_on_sveltekit_with_unsupported_adapter(the previous behavior of silently falling through to Vite was the bug)All SvelteKit detection tests pass;
cargo clippyis clean.