read-only property 🟨 JavaScript

TypeError: Cannot assign to read only property 'x' of object

Code tried to modify a frozen object, a getter-only property, or immutable state.

Seen on: JavaScript

Meaning

Object.freeze, Redux Toolkit/Immer frozen state, and module namespace objects are read-only in strict mode.

Common causes

  • Mutating frozen state (Redux/Immer)
  • Assigning to a getter-only property
  • Modifying an ES module export

⚡ Quick fix

  1. Create a copy instead of mutating
  2. Use the setter/action provided
  3. Update state immutably

Detailed fix by platform

JavaScript

  1. const next = { ...state, count: state.count + 1 };

How to diagnose

  1. Object — Frozen or getter-only?
  2. Owner — Which library froze it?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.