このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

TypeError: "x" is not a non-null object

JavaScript の例外 "is not a non-null object" は、ある場所でオブジェクトが期待されているのに提供されなかった場合に発生します。 null はオブジェクトではなく、動作しません。

エラーメッセージ

TypeError: Property description must be an object: x (V8-based)
TypeError: Property descriptor must be an object, got "x" (Firefox)
TypeError: Property description must be an object. (Safari)

エラー型

TypeError

エラーの原因

ある場所でオブジェクトが期待されていますが、提供されませんでした。 null はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。

例

プロパティ記述子が求められている場合

Object.create() メソッドや Object.defineProperty() メソッド、Object.defineProperties() メソッドを使用するとき、省略可能な記述子の引数として、プロパティ記述子オブジェクトが想定されます。 (ただの数値など) オブジェクト以外のものを提供すると、エラーが発生します。

js
Object.defineProperty({}, "key", 1);
// TypeError: 1 is not a non-null object

Object.defineProperty({}, "key", null);
// TypeError: null is not a non-null object

有効なプロパティ記述子はこのようになります。

js
Object.defineProperty({}, "key", { value: "foo", writable: false });

関連情報