{"record":{"id":"c568871e588525af","repo":"sveltejs/svelte","slug":"async-derived-orphan","errorCode":"async_derived_orphan","errorMessage":"async_derived_orphan\nCannot create a `$derived(...)` with an `await` expression outside of an effect tree\nhttps://svelte.dev/e/async_derived_orphan","messagePattern":"async_derived_orphan\nCannot create a `\\$derived\\(\\.\\.\\.\\)` with an `await` expression outside of an effect tree\nhttps://svelte\\.dev/e/async_derived_orphan","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/internal/client/errors.js","lineNumber":17,"sourceCode":"/* This file is generated by scripts/process-messages/index.js. Do not edit! */\n\nimport { DEV } from 'esm-env';\n\nexport *  from '../shared/errors.js';\n\n/**\n * Cannot create a `$derived(...)` with an `await` expression outside of an effect tree\n * @returns {never}\n */\nexport function async_derived_orphan() {\n\tif (DEV) {\n\t\tconst error = new Error(`async_derived_orphan\\nCannot create a \\`$derived(...)\\` with an \\`await\\` expression outside of an effect tree\\nhttps://svelte.dev/e/async_derived_orphan`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/async_derived_orphan`);\n\t}\n}\n\n/**\n * Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead\n * @returns {never}\n */\nexport function bind_invalid_checkbox_value() {\n\tif (DEV) {\n\t\tconst error = new Error(`bind_invalid_checkbox_value\\nUsing \\`bind:value\\` together with a checkbox input is not allowed. Use \\`bind:checked\\` instead\\nhttps://svelte.dev/e/bind_invalid_checkbox_value`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/bind_invalid_checkbox_value`);","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/internal/client/errors.js#L1-L35","documentation":"Runtime error `async_derived_orphan`: a `$derived(...)` expression contains an `await`, but the derived was not created inside an effect (`$effect`) tree. Svelte disallows orphan async deriveds because there is no owner effect to manage the async lifecycle. In production only the URL is thrown; in DEV the full message is shown.","triggerScenarios":"At runtime, evaluating `$derived(await fetch(...))` (or any `$derived` whose expression contains `await`) at the top level of a component or in a context that is not inside an `$effect`/`$effect.root`. The derived has no parent effect to own the async work.","commonSituations":"Migrating reactive statements that performed async work into `$derived` instead of `$effect`; using `$derived` to compute a value from a promise at component init; calling async helpers inside a derived in a snippet or store factory.","solutions":["Move the async work into an `$effect` (or `$effect.pre`) and store the result in a `$state` variable that the derived reads.","Ensure the `$derived` is created inside an `$effect.root` if you genuinely need a detached async derived.","Refactor to a derived that reads an already-resolved value (e.g. combine with `{#await}` in the template)."],"exampleFix":"// before\nlet data = $derived(await fetch('/api').then(r => r.json()));\n\n// after\nlet data = $state();\n$effect(() => {\n  fetch('/api').then(r => r.json()).then(v => data = v);\n});","handlingStrategy":"validation","validationCode":"// Structural check: ensure no $derived body contains a top-level await at component scope.\n// (Best done as an ESLint rule or a pre-commit grep on the source.)\nfunction riskyAsyncDerived(source) {\n  return /\\$derived\\s*\\(\\s*(?:async\\s|\\(?\\s*await)/.test(source);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never put `await` inside a `$derived` — async work belongs in `$effect` writing to `$state`.","Use `{#await}` in markup to render promise results.","For detached async work, wrap the owner in `$effect.root`."],"tags":["svelte5","runes","derived","async","runtime","effects"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}