{"record":{"id":"0d56ea8408af07fc","repo":"codex-team/editor.js","slug":"constructors-for-abstract-class-module-are-not-all","errorCode":null,"errorMessage":"Constructors for abstract class Module are not allowed.","messagePattern":"Constructors for abstract class Module are not allowed\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"critical","filePath":"src/components/__module.ts","lineNumber":101,"sourceCode":"\n      this.mutableListenerIds = [];\n    },\n  };\n\n  /**\n   * The set of listener identifiers which will be dropped in read-only mode\n   */\n  private mutableListenerIds: string[] = [];\n\n  /**\n   * @class\n   * @param options - Module options\n   * @param options.config - Module config\n   * @param options.eventsDispatcher - Common event bus\n   */\n  constructor({ config, eventsDispatcher }: ModuleConfig) {\n    if (new.target === Module) {\n      throw new TypeError('Constructors for abstract class Module are not allowed.');\n    }\n\n    this.config = config;\n    this.eventsDispatcher = eventsDispatcher;\n  }\n\n  /**\n   * Editor modules setter\n   *\n   * @param {EditorModules} Editor - Editor's Modules\n   */\n  public set state(Editor: EditorModules) {\n    this.Editor = Editor;\n  }\n\n  /**\n   * Remove memorized nodes\n   */","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/codex-team/editor.js/blob/5f45dabbe5690b7033b2f9047d3985add5045fdd/src/components/__module.ts#L83-L119","documentation":"Module is the abstract base class all Editor.js modules extend. Its constructor guards against direct instantiation with new.target: creating a `new Module(...)` directly throws this TypeError. Only subclasses (BlockManager, Tools, etc.) may call super() through their own constructors.","triggerScenarios":"Calling `new Module(config)` directly in user code or in a test; a subclass whose constructor is invoked with Module as new.target (e.g. via Reflect.construct(Module, args) without a newTarget argument).","commonSituations":"Custom tooling/tests that try to instantiate the base class; copying module scaffolding code and forgetting to extend Module; monkey-patching or Reflect.construct usage that loses the subclass new.target.","solutions":["Instantiate a concrete subclass (e.g. `new BlockManager({...})`) instead of Module itself","If writing a custom module, declare `class MyModule extends Module` and instantiate MyModule","If using Reflect.construct, pass the subclass as the newTarget parameter: Reflect.construct(Module, args, MyModule)"],"exampleFix":"// before\nconst m = new Module({ config, eventsDispatcher });\n// after\nclass MyModule extends Module {}\nconst m = new MyModule({ config, eventsDispatcher });","handlingStrategy":"type-guard","validationCode":"if (Module === target || !(target.prototype instanceof Module)) { throw new TypeError('Instantiate a Module subclass'); }","typeGuard":"const isModuleSubclass = (C: unknown): C is typeof Module => typeof C === 'function' && C.prototype instanceof Module && C !== Module;","tryCatchPattern":"try { new Module(cfg); } catch (e) { if (e instanceof TypeError && /abstract class Module/.test(e.message)) { /* instantiate a subclass instead */ } throw e; }","preventionTips":["Always extend Module for custom modules","Never Reflect.construct(Module, args) without the subclass newTarget"],"tags":["abstract-class","constructor","typescript","new-target"],"backgroundTag":"abstract-class-instantiation","analyzedSha":"5f45dabbe5690b7033b2f9047d3985add5045fdd","analyzedAt":"2026-08-27T22:50:23.124Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}