diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 76d68086c841..b59e0631a938 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -1,5 +1,6 @@ import { custom_event, append, append_hydration, insert, insert_hydration, detach, listen, attr } from './dom'; import { SvelteComponent } from './Component'; +import { current_component } from './lifecycle'; export function dispatch_dev(type: string, detail?: T) { document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail }, true)); @@ -155,6 +156,13 @@ export class SvelteComponentDev extends SvelteComponent { throw new Error("'target' is a required option"); } + if (!options.target && !current_component) { + throw new Error( + 'Multiple Svelte instances detected. This can happen if you use Svelte components which are precompiled to JavaScript. ' + + "Ensure to use the raw Svelte version of these components, or set the 'target' option instead" + ); + } + super(); }