From 5cecb98484b5e1cf7ed2890078a4930eab8f6e7e Mon Sep 17 00:00:00 2001 From: gitea Date: Sat, 14 Feb 2026 12:31:05 +0100 Subject: [PATCH] fix issue --- src/main.js | 14 +++++++++----- vite.config.js | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.js b/src/main.js index 458c7a8..5eab415 100644 --- a/src/main.js +++ b/src/main.js @@ -1,9 +1,13 @@ -import { mount } from 'svelte' import './app.css' -import App from './App.svelte' -const app = mount(App, { - target: document.getElementById('app'), -}) +// Only load and mount the app in a real browser (document + mount available). +// Avoids "mount() is not available on the server" when the bundle runs in SSR/workers. +let app = null +const target = typeof document !== 'undefined' && document.getElementById('app') +if (target) { + const { mount } = await import('svelte') + const { default: App } = await import('./App.svelte') + app = mount(App, { target }) +} export default app diff --git a/vite.config.js b/vite.config.js index d1b7607..a9df04c 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,8 +5,8 @@ import { svelte } from '@sveltejs/vite-plugin-svelte' export default defineConfig(({ mode }) => ({ plugins: [svelte()], resolve: { - // Use browser Svelte build in tests so mount() is available (avoid "lifecycle_function_unavailable") - conditions: mode === 'test' ? ['browser'] : [], + // Prefer browser Svelte build so mount() is available (avoid "lifecycle_function_unavailable" on server/workers) + conditions: ['browser'], }, test: { include: ['src/**/*.{test,spec}.{js,ts}'],