Get to know MDN better
The JavaScript exception "WeakSet key (or WeakMap value) 'x' must be an object or an unregistered symbol" occurs when a value of invalid type is used as a key in a WeakSet or as a value in a WeakMap.
WeakSet and WeakMap require the keys to be garbage collectable. Only objects and non-registered symbols (that is, symbols not returned by Symbol.for()) are valid. For more information, see Memory management. If you want to add keys that are strings, numbers, or other primitive values, you should store them in a regular Set or Map instead.
This page was last modified on Aug 15, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.