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

SSR disabled and sveltekit still tries to execute .js files serverside #1879

Closed
gigitalz opened this issue Jul 11, 2021 · 2 comments
Closed

Comments

@gigitalz
Copy link

gigitalz commented Jul 11, 2021

Not sure if it's an issue or a question but I disabled ssr from the svelte.config.js file.
I am using the adapter static version "1.0.0-next.13" and @sveltejs/kit "next".

I still have to use tricks during development on the vite server, for example the following so that the code is not executed on the server. Why is this code still executed server side?
Some packages I use will return errors like "Websocket not defined" if I run them on the server. There is really no point for me to develop while code is executed ssr if I am just producing a static SPA, so how to disable all that?

try {
	process.browser
} catch (e) { //Will run only in the browser

}

this is my config:

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

const config = {
	kit: {
		// hydrate the <div id="svelte"> element in src/app.html
		ssr: false,
		target: '#svelte',
		adapter: adapter({
			pages: 'build',
			assets: 'build',
			fallback: null
		}),

		trailingSlash: 'ignore',
		paths: {
			assets: '',
			base: '/bot'
		},

		vite: () => ({
			ssr: {
				noExternal: ['svelte-hero-icons']
			},
			optimizeDeps: {
				include: ['svelte-hero-icons']
			},
			base: "/bot",
			server: {
				hmr: true,
				watch: {
					usePolling: true,
					interval: 500
				}
			}
		})
	}
};

export default config;
12:23:39 [vite] Error when evaluating SSR module /src/lib/websocket.js:
ReferenceError: WebSocket is not defined
@gigitalz
Copy link
Author

I suspect my issue is related to #1650.

@benmccann
Copy link
Member

Yes. I'm going to close this as a duplicate of that issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants