We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

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

Our volunteers haven't translated this article into 한국어 yet. Join us and help get the job done!
You can also read the article in English (US).


TypeError: can't redefine non-configurable property "x" (Firefox)
TypeError: Cannot redefine property: "x" (Chrome)

Error type


What went wrong?

It was attempted to redefine a property, but that property is non-configurable. The configurable attribute controls whether the property can be deleted from the object and whether its attributes (other than writable) can be changed. Usually, properties in an object created by an object initializer are configurable. However, for example, when using Object.defineProperty(), the property isn't configurable by default.


Non-configurable properties created by Object.defineProperty

The Object.defineProperty() creates non-configurable properties if you haven't specified them as configurable.

var 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 it later in the code.

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

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz
 최종 변경: fscholz,