{"record":{"id":"20440eceb7ac13d4","repo":"sveltejs/svelte","slug":"state-descriptors-fixed","errorCode":"state_descriptors_fixed","errorMessage":"state_descriptors_fixed\nProperty descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.\nhttps://svelte.dev/e/state_descriptors_fixed","messagePattern":"state_descriptors_fixed\nProperty descriptors defined on `\\$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`\\.\nhttps://svelte\\.dev/e/state_descriptors_fixed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/internal/client/errors.js","lineNumber":460,"sourceCode":"\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/set_context_after_init`);\n\t}\n}\n\n/**\n * Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.\n * @returns {never}\n */\nexport function state_descriptors_fixed() {\n\tif (DEV) {\n\t\tconst error = new Error(`state_descriptors_fixed\\nProperty descriptors defined on \\`$state\\` objects must contain \\`value\\` and always be \\`enumerable\\`, \\`configurable\\` and \\`writable\\`.\\nhttps://svelte.dev/e/state_descriptors_fixed`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/state_descriptors_fixed`);\n\t}\n}\n\n/**\n * Cannot set prototype of `$state` object\n * @returns {never}\n */\nexport function state_prototype_fixed() {\n\tif (DEV) {\n\t\tconst error = new Error(`state_prototype_fixed\\nCannot set prototype of \\`$state\\` object\\nhttps://svelte.dev/e/state_prototype_fixed`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/state_prototype_fixed`);\n\t}\n}","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/internal/client/errors.js#L442-L478","documentation":"Thrown at internal/client/proxy.js:125 in the Proxy defineProperty trap of a $state object. Svelte's state proxy requires descriptors to carry a concrete `value` and to be enumerable, configurable, and writable, because it maintains per-property signal sources and must satisfy Proxy invariants when forking; accessor descriptors or frozen descriptors would break reactivity and fork semantics.","triggerScenarios":"Calling Object.defineProperty(stateObj, 'key', { get() {...} }) or a descriptor with configurable:false / enumerable:false / writable:false on a $state-proxied object. The guard at proxy.js:114-126 rejects any descriptor lacking `value` or with any of the three flags false.","commonSituations":"Using Object.defineProperty to add getters to state; freezing parts of state via property descriptors; libraries that define read-only descriptors on received objects; porting class-based state with accessor properties.","solutions":["Use a plain assignment (`stateObj.key = value`) instead of Object.defineProperty for reactive properties.","If you need a getter, expose it via $derived or a computed function rather than a descriptor on the $state object.","Keep the descriptor as { value, writable: true, enumerable: true, configurable: true } if you must use defineProperty."],"exampleFix":"// before\nconst state = $state({});\nObject.defineProperty(state, 'x', { get: () => 1 }); // throws\n\n// after\nconst state = $state({ _x: 1 });\nconst x = $derived(state._x); // derive instead","handlingStrategy":"validation","validationCode":"// Do not use accessor/frozen descriptors on $state objects.\n// Acceptable shape only:\n// Object.defineProperty(state, 'k', { value: 1, writable: true, enumerable: true, configurable: true });\n// Prefer plain assignment: state.k = 1;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain assignment instead of Object.defineProperty on $state objects.","Express computed values via $derived, not accessor descriptors.","If a library calls defineProperty on objects you pass, pass a non-state clone to it."],"tags":["svelte","runes","state","proxy","defineproperty"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}