{"record":{"id":"9f922c327e1999c8","repo":"chartjs/Chart.js","slug":"class-does-not-have-id-item","errorCode":null,"errorMessage":"class does not have id: ${item}","messagePattern":"class does not have id: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/core.typedRegistry.js","lineNumber":38,"sourceCode":"  /**\n\t * @param {IChartComponent} item\n\t * @returns {string} The scope where items defaults were registered to.\n\t */\n  register(item) {\n    const proto = Object.getPrototypeOf(item);\n    let parentScope;\n\n    if (isIChartComponent(proto)) {\n      // Make sure the parent is registered and note the scope where its defaults are.\n      parentScope = this.register(proto);\n    }\n\n    const items = this.items;\n    const id = item.id;\n    const scope = this.scope + '.' + id;\n\n    if (!id) {\n      throw new Error('class does not have id: ' + item);\n    }\n\n    if (id in items) {\n      // already registered\n      return scope;\n    }\n\n    items[id] = item;\n    registerDefaults(item, scope, parentScope);\n    if (this.override) {\n      defaults.override(item.id, item.overrides);\n    }\n\n    return scope;\n  }\n\n  /**\n\t * @param {string} id","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/chartjs/Chart.js/blob/cb02e1d207bd4c4c40b20c259017f85f26f1e30a/src/core/core.typedRegistry.js#L20-L56","documentation":"TypedRegistry.register(item) requires item.id to be a truthy string; without it the registry cannot scope defaults (scope + '.' + id) or store the component. The error stringifies the offending item so you can see what was passed. It is thrown when Chart.register(...) (or auto-registration) receives a class/object lacking a static `id` property.","triggerScenarios":"Calling Chart.register(MyClass) where MyClass has no static `id`; registering a plain object instead of a component class with an id; a custom plugin/scale/element/controller defined without an `id` static field; passing undefined/null into register() (e.g. a failed dynamic import).","commonSituations":"Authoring a custom Chart.js component and forgetting `static id = 'myThing'`; refactoring that renames/removes the id; bundler tree-shaking removing the static id assignment; copy-pasting a plugin snippet that omitted the id.","solutions":["Add a static id to the component class: `class MyScale extends Scale { static id = 'myScale'; static defaults = {}; }`.","Confirm every argument passed to Chart.register(...) is a class/object with a string `id`.","Guard dynamic imports: only register when the imported value is defined and has an id.","If registering an object form, ensure it has an `id` key (e.g. Chart.register({ id: 'myPlugin', ... }))."],"exampleFix":"// before\nclass MyPlugin {\n  afterDraw(chart) { /* ... */ }\n}\nChart.register(MyPlugin); // no static id -> throws\n\n// after\nclass MyPlugin {\n  static id = 'myPlugin';\n  afterDraw(chart) { /* ... */ }\n}\nChart.register(MyPlugin);","handlingStrategy":"validation","validationCode":"// Validate that every item passed to Chart.register has an id.\nimport { Chart } from 'chart.js';\n\nfunction registerSafely(...items) {\n  for (const item of items) {\n    if (!item || typeof item !== 'function' && typeof item !== 'object') {\n      throw new Error('Chart.register received a non-component: ' + String(item));\n    }\n    if (!item.id || typeof item.id !== 'string') {\n      throw new Error('Component missing static id: ' + (item.name || String(item)));\n    }\n  }\n  Chart.register(...items);\n}","typeGuard":"// Type guard ensuring a component class/object has an id.\nfunction isRegistrableComponent(c) {\n  return Boolean(c) && (typeof c === 'function' || typeof c === 'object') && typeof c.id === 'string' && c.id.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always declare `static id = '...';` on custom Chart.js components.","Wrap Chart.register in a project helper that checks for an id.","Unit-test custom plugins/scales by constructing and registering them in isolation.","Beware bundlers that drop static class fields; target ES2015+ for static field semantics."],"tags":["registry","custom-component","plugin","configuration"],"backgroundTag":null,"analyzedSha":"cb02e1d207bd4c4c40b20c259017f85f26f1e30a","analyzedAt":"2026-08-12T23:38:10.965Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}