Open
Description
Describe the bug
Hi team,
I am not sure whether this is a bug, not supported or me not having proper configuration. I hope that you or someone is able to help me with clarification.
The requirement I am trying to satisfy is externally compiled and hosted Svelte widgets that can be loaded into my SvelteKit app but when I try to dynamically import and load the Svelte widgets, I get the following error.

I can see that the dynamically loaded component taps into the svelte runtime within the sveltekit project, so I got that going for me :)
Looking forward to hear from someone.
Reproduction
1st Repo with Component
- Create a barebone vite & svelte 5 project
- Create Counter component at
src/lib/Counter.svelte
. npm run build
- use http-server to host server counter.js:
http-server dist --cors
Counter.svelte
<script lang="ts">
let count: number = $state(0);
const increment = () => {
count += 1;
};
</script>
<button onclick={increment}>
count is {count}
</button>
vite.config.js
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
export default defineConfig({
plugins: [svelte()],
build: {
lib: {
entry: './src/lib/Counter.svelte',
formats: ['es'],
fileName: 'counter',
},
rollupOptions: {
external: ['svelte', 'svelte/internal'],
output: {
globals: {
svelte: 'Svelte',
},
},
},
},
});
2nd Repo with barebone SvelteKit setup
- Create DynamicComponent at
src/lib/DynamicComponent.svelte
- Render DyanamicComponent in routes/+page.svelte:
<DynamicComponent componentUrl="http://localhost:8080/counter.js" />
- Start dev server:
npm run dev
DynamicaComponent.svelte
<script lang="ts">
export let componentUrl: string;
</script>
{#await import(componentUrl)}
<div>Loading...</div>
{:then Component}
<!-- Dynamically loaded component -->
<Component.default />
{:catch error}
<div>Error loading component: {error.message}</div>
{/await}
Both repos have svelte 5 installed.
Logs
No response
System Info
Repo 1:
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
"@tsconfig/svelte": "^5.0.4",
"svelte": "^5.0.0-next.244",
"svelte-check": "^3.8.5",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"vite": "^5.4.1"
}
Repo 2
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
"@types/eslint": "^9.6.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^5.0.0-next.1",
"svelte-check": "^4.0.0",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0",
"vite": "^5.0.3",
"vitest": "^2.0.0"
},
Severity
blocking all usage of svelte
Metadata
Metadata
Assignees
Labels
No labels