{"record":{"id":"21c9c94fc52f1cbf","repo":"sveltejs/svelte","slug":"rune-outside-svelte","errorCode":"rune_outside_svelte","errorMessage":"rune_outside_svelte\nThe `${rune}` rune is only available inside `.svelte` and `.svelte.js/ts` files\nhttps://svelte.dev/e/rune_outside_svelte","messagePattern":"rune_outside_svelte\nThe `(.+?)` rune is only available inside `\\.svelte` and `\\.svelte\\.js/ts` files\nhttps://svelte\\.dev/e/rune_outside_svelte","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/internal/client/errors.js","lineNumber":428,"sourceCode":"\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/props_rest_readonly`);\n\t}\n}\n\n/**\n * The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files\n * @param {string} rune\n * @returns {never}\n */\nexport function rune_outside_svelte(rune) {\n\tif (DEV) {\n\t\tconst error = new Error(`rune_outside_svelte\\nThe \\`${rune}\\` rune is only available inside \\`.svelte\\` and \\`.svelte.js/ts\\` files\\nhttps://svelte.dev/e/rune_outside_svelte`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/rune_outside_svelte`);\n\t}\n}\n\n/**\n * `setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression\n * @returns {never}\n */\nexport function set_context_after_init() {\n\tif (DEV) {\n\t\tconst error = new Error(`set_context_after_init\\n\\`setContext\\` must be called when a component first initializes, not in a subsequent effect or after an \\`await\\` expression\\nhttps://svelte.dev/e/set_context_after_init`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/set_context_after_init`);\n\t}\n}","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/internal/client/errors.js#L410-L446","documentation":"Thrown at index-client.js:29 via a global getter trap installed by throw_rune_error(). Outside a .svelte, .svelte.js, or .svelte.ts file the compiler never rewrites rune calls ($state, $effect, $derived, $inspect, $props, $bindable) into runtime APIs; instead a global getter is installed that throws this error so misuse fails loudly rather than silently being treated as a plain identifier.","triggerScenarios":"Writing `$state(0)` or any other rune in a plain .js / .ts / .mjs file. Because the compiler only processes .svelte* files, the rune is left as-is, resolves to the trapped global, and throws on access.","commonSituations":"Extracting reactive logic into a utility and forgetting to rename the file to .svelte.js; copy-pasting runes code into a plain module; importing a runes-using helper from a non-svelte file that was renamed.","solutions":["Rename the file to .svelte.js or .svelte.ts so the compiler processes the runes.","If the file must stay plain .js, do not use runes — pass reactive values in/out via function parameters and return values.","Move the runes-using code into a .svelte component or .svelte.js module."],"exampleFix":"// before — utils.js (plain)\nexport const count = $state(0); // throws\n\n// after — rename to utils.svelte.js\nexport const count = $state(0); // compiler rewrites to runtime API","handlingStrategy":"validation","validationCode":"// Use runes only in .svelte, .svelte.js, or .svelte.ts files.\n// Check file extension before writing runes:\nimport path from 'node:path';\nfunction canUseRunes(file) {\n  return /\\.svelte(\\.js|\\.ts)?$/.test(path.extname(file));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name any module that uses runes with a .svelte.js or .svelte.ts extension.","Keep non-reactive utilities in plain .js/.ts and pass reactive values via parameters.","Configure your bundler/editor to treat .svelte.js files as compiled."],"tags":["svelte","runes","compiler","file-extension","configuration"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}