I needed a specific route in my app to not be server-side rendered. This can be achieved by setting export const ssr = false
in the module script or configuring ssr: false
in the svelte.config.js
, as outlined in the Svelte documentation.
Despite disabling SSR using both methods, I encountered errors in the terminal such as localStorage is not defined
, which should not occur with SSR disabled.
The app continues to function properly. However, whenever I reload the page in the browser, this error reappears in the terminal.
[vite] Error when evaluating SSR module /src/routes/index.svelte:
ReferenceError: localStorage is not defined
svelte.config.js
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
ssr: false,
adapter: adapter({
fallback: '200.html'
}),
prerender: {
enabled: false
},
}
};
export default config;
index.svelte
<script context="module" lang="ts">
export const ssr = false
</script>
<script lang="ts">
import Yrtc from "./../helpers/Yrtc";
import { onMount } from "svelte";
onMount(() => {
const yrtc = new Yrtc({
roomId: 'tet-riieiiasds-di'
})
console.log({yrtc})
})
</script>
test