sveltejs/svelte · error · Error

state_descriptors_fixed

state_descriptors_fixed

Error message

state_descriptors_fixed
Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
https://svelte.dev/e/state_descriptors_fixed

What it means

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.

Source

Thrown at packages/svelte/src/internal/client/errors.js:460

		throw error;
	} else {
		throw new Error(`https://svelte.dev/e/set_context_after_init`);
	}
}

/**
 * Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
 * @returns {never}
 */
export function state_descriptors_fixed() {
	if (DEV) {
		const 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`);

		error.name = 'Svelte error';

		throw error;
	} else {
		throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
	}
}

/**
 * Cannot set prototype of `$state` object
 * @returns {never}
 */
export function state_prototype_fixed() {
	if (DEV) {
		const error = new Error(`state_prototype_fixed\nCannot set prototype of \`$state\` object\nhttps://svelte.dev/e/state_prototype_fixed`);

		error.name = 'Svelte error';

		throw error;
	} else {
		throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
	}
}

View on GitHub (pinned to 20b341f100)

Solutions

  1. Use a plain assignment (`stateObj.key = value`) instead of Object.defineProperty for reactive properties.
  2. If you need a getter, expose it via $derived or a computed function rather than a descriptor on the $state object.
  3. Keep the descriptor as { value, writable: true, enumerable: true, configurable: true } if you must use defineProperty.

Example fix

// before
const state = $state({});
Object.defineProperty(state, 'x', { get: () => 1 }); // throws

// after
const state = $state({ _x: 1 });
const x = $derived(state._x); // derive instead
Defensive patterns

Strategy: validation

Validate before calling

// Do not use accessor/frozen descriptors on $state objects.
// Acceptable shape only:
// Object.defineProperty(state, 'k', { value: 1, writable: true, enumerable: true, configurable: true });
// Prefer plain assignment: state.k = 1;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sveltejs/svelte@20b341f100 (2026-08-12). Data as JSON: /api/errors/20440eceb7ac13d4. Report an issue: GitHub.