Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. JavaScript error reference
  5. TypeError: can't redefine non-configurable property "x"

TypeError: can't redefine non-configurable property "x"

The JavaScript exception "can't redefine non-configurable property" occurs when it wasattempted to redefine a property, but that property isnon-configurable.

Message

TypeError: Cannot redefine property: "x" (V8-based)TypeError: can't redefine non-configurable property "x" (Firefox)TypeError: Attempting to change value of a readonly property. (Safari)

Error type

TypeError

What went wrong?

It was attempted to redefine a property, but that property isnon-configurable. Theconfigurable attribute controls whether the property can be deleted fromthe object and whether its attributes (other thanwritable) can be changed.Usually, properties in an object created by anobject initializer are configurable. However, for example, when usingObject.defineProperty(), the property isn't configurable by default.

Examples

Non-configurable properties created by Object.defineProperty

TheObject.defineProperty() creates non-configurable properties if youhaven't specified them as configurable.

js
const obj = Object.create({});Object.defineProperty(obj, "foo", { value: "bar" });Object.defineProperty(obj, "foo", { value: "baz" });// TypeError: can't redefine non-configurable property "foo"

You will need to set the "foo" property to configurable, if you intend to redefine itlater in the code.

js
const obj = Object.create({});Object.defineProperty(obj, "foo", { value: "bar", configurable: true });Object.defineProperty(obj, "foo", { value: "baz", configurable: true });

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp