{"record":{"id":"61ab5e8fea439dd7","repo":"liabru/matter-js","slug":"plugin-register-is-already-registered-to-differen","errorCode":null,"errorMessage":"Plugin.register: is already registered to different plugin object","messagePattern":"Plugin\\.register: is already registered to different plugin object","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/core/Plugin.js","lineNumber":39,"sourceCode":"     * @return {object} The plugin.\n     */\n    Plugin.register = function(plugin) {\n        if (!Plugin.isPlugin(plugin)) {\n            Common.warn('Plugin.register:', Plugin.toString(plugin), 'does not implement all required fields.');\n        }\n\n        if (plugin.name in Plugin._registry) {\n            var registered = Plugin._registry[plugin.name],\n                pluginVersion = Plugin.versionParse(plugin.version).number,\n                registeredVersion = Plugin.versionParse(registered.version).number;\n\n            if (pluginVersion > registeredVersion) {\n                Common.warn('Plugin.register:', Plugin.toString(registered), 'was upgraded to', Plugin.toString(plugin));\n                Plugin._registry[plugin.name] = plugin;\n            } else if (pluginVersion < registeredVersion) {\n                Common.warn('Plugin.register:', Plugin.toString(registered), 'can not be downgraded to', Plugin.toString(plugin));\n            } else if (plugin !== registered) {\n                Common.warn('Plugin.register:', Plugin.toString(plugin), 'is already registered to different plugin object');\n            }\n        } else {\n            Plugin._registry[plugin.name] = plugin;\n        }\n\n        return plugin;\n    };\n\n    /**\n     * Resolves a dependency to a plugin object from the registry if it exists. \n     * The `dependency` may contain a version, but only the name matters when resolving.\n     * @method resolve\n     * @param dependency {string} The dependency.\n     * @return {object} The plugin if resolved, otherwise `undefined`.\n     */\n    Plugin.resolve = function(dependency) {\n        return Plugin._registry[Plugin.dependencyParse(dependency).name];\n    };","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/liabru/matter-js/blob/acb99b6f8784c809b940f1d2cf745427e088e088/src/core/Plugin.js#L21-L57","documentation":"A plugin with the same name and the SAME version is already registered, but it is a different object reference than the one being registered. The registry keeps the original; the second registration is ignored with a warning. This usually indicates duplicate module instantiation (the plugin file was evaluated twice, creating two distinct but identical objects).","triggerScenarios":"Loading the plugin script twice without a version bump; bundler duplicating the module into two chunks so require/import yields two distinct objects; re-registering a re-created object of equal version.","commonSituations":"Mixing CDN script and bundled copy of the same plugin; multiple <script> tags; module federation/commonjs+esm dual loading.","solutions":["Register the plugin only once; guard with if (!Plugin._registry['name']) or remove duplicate script includes.","Dedupe the module in your bundler so all code shares one plugin instance.","If both objects are genuinely equivalent, this warning is safe to ignore — the first registration is used.","Bump the version if you intentionally ship a new plugin object."],"exampleFix":"// before\nPlugin.register(pluginObjA); // v1.0.0\nPlugin.register(pluginObjB); // v1.0.0 but different object\n// after\nif (!Matter.Plugin._registry['my-plugin']) {\n  Plugin.register(pluginObjA);\n}","handlingStrategy":"validation","validationCode":"if (!Matter.Plugin._registry[plugin.name]) {\n  Matter.Plugin.register(plugin);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register plugins once at app bootstrap","Avoid loading the plugin via both script tag and bundler import","Dedupe modules in your bundler config","Same name+version but different object = module evaluated twice; fix loading, not the plugin"],"tags":["plugin","duplicate","module-loading"],"backgroundTag":"duplicate-plugin-registration","analyzedSha":"acb99b6f8784c809b940f1d2cf745427e088e088","analyzedAt":"2026-09-02T21:29:27.057Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}