pbakaus/impeccable · error · Error
SvelteKit live adapter requires a numeric port
Error message
SvelteKit live adapter requires a numeric port
What it means
Thrown by applySvelteKitLiveAdapter when the port argument cannot be coerced to a finite number. The adapter writes the live mount component with the port baked in, so a non-numeric port would produce a broken component; the guard fails fast before touching any files.
Source
Thrown at plugin/skills/impeccable/scripts/live/sveltekit-adapter.mjs:64
if (!hasTemplateMarkers) return null;
const hasSvelteConfig = fs.existsSync(path.join(cwd, 'svelte.config.js'))
|| fs.existsSync(path.join(cwd, 'svelte.config.mjs'))
|| fs.existsSync(path.join(cwd, 'svelte.config.cjs'))
|| fs.existsSync(path.join(cwd, 'svelte.config.ts'));
const hasKitPackage = packageHasSvelteKit(cwd);
if (!hasSvelteConfig && !hasKitPackage) return null;
return {
appHtml,
layoutFile: findSvelteKitLayout(cwd),
rootComponent: SVELTE_LIVE_ROOT_COMPONENT,
};
}
export function applySvelteKitLiveAdapter({ cwd = process.cwd(), port, token, config = null } = {}) {
if (!Number.isFinite(Number(port))) {
throw new Error('SvelteKit live adapter requires a numeric port');
}
const detected = detectSvelteKitProject(cwd, config);
if (!detected) return null;
ensureSvelteLiveRootComponent(cwd, Number(port), token);
const layoutRel = detected.layoutFile;
const layoutAbs = path.join(cwd, layoutRel);
fs.mkdirSync(path.dirname(layoutAbs), { recursive: true });
const layoutExisted = fs.existsSync(layoutAbs);
const before = layoutExisted ? fs.readFileSync(layoutAbs, 'utf-8') : defaultSvelteLayout();
const after = patchSvelteLayout(before, { rev: svelteAdapterRev(token) });
fs.writeFileSync(layoutAbs, after, 'utf-8');
return {
file: layoutRel,
adapter: 'sveltekit',
inserted: after !== before || !layoutExisted,View on GitHub (pinned to d14711ae3d)
Solutions
- Pass a numeric port: applySvelteKitLiveAdapter({ port: 4321 }).
- Coerce from env: port: Number(process.env.IMPECCABLE_PORT) and validate it is finite before calling.
- Ensure the boot flow assigns a concrete port before invoking the adapter.
Example fix
// before
applySvelteKitLiveAdapter({ cwd, port: undefined, token });
// after
const port = Number(process.env.IMPECCABLE_PORT ?? 4321);
if (!Number.isFinite(port)) throw new Error('port must be numeric');
applySvelteKitLiveAdapter({ cwd, port, token }); Defensive patterns
Strategy: validation
Validate before calling
function isValidPort(port) {
const n = Number(port);
return Number.isFinite(n) && n > 0 && n < 65536;
} Type guard
function isNumericPort(port) {
return Number.isFinite(Number(port));
} Try / catch
try {
applySvelteKitLiveAdapter({ cwd, port, token });
} catch (err) {
if (err.message === 'SvelteKit live adapter requires a numeric port') {
port = 4321; // default and retry
applySvelteKitLiveAdapter({ cwd, port, token });
} else throw err;
} Prevention
- Always coerce port via Number() and validate with Number.isFinite before calling the adapter.
- Default the port in the boot flow so undefined never reaches the adapter.
- Reject ports outside 1-65535 upstream for a clearer error.
When it happens
Trigger: Calling applySvelteKitLiveAdapter({ port: undefined }), port: null, port: 'abc', or port: NaN. Number(port) is non-finite and the throw fires before detectSvelteKitProject.
Common situations: The boot did not parse a --port flag, an env var (PORT) was unset and flowed through as undefined, or a string port was passed uncoerced.
Related errors
- TanStack Start live adapter requires a numeric port
- SvelteKit live adapter requires a numeric port
- --target requires a path value (use --target <path> or --tar
- Invalid svelte-component source file
- Svelte-component source file escapes project root
AI-assisted analysis of pbakaus/impeccable@d14711ae3d (2026-08-13).
Data as JSON: /api/errors/1a6569b307d71148.
Report an issue: GitHub.