{"record":{"id":"0782628415e3b3c4","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-add-module-modulename-because-it-has-depe","errorCode":null,"errorMessage":"Cannot add module {moduleName} because it has dependencies on other modules that are not present: {string.Join(\", \", missingDependencyNames)}","messagePattern":"Cannot add module (.+?) because it has dependencies on other modules that are not present: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Modules/PostStrippingModuleAdder.cs","lineNumber":63,"sourceCode":"        {\n            if (!IsModuleIncluded(dependency))\n            {\n                missingDependencyNames.Add(dependency);\n\n                //no need to process this entry further as it is missing from the included module list\n                continue;\n            }\n\n            moduleDependencies.Add(new LinkerToEditorData.ReportData.Dependency\n            {\n                name = dependency,\n                dependencyType = LinkerToEditorData.ReportData.DependencyType.Custom,\n                scenes = Array.Empty<string>(),\n            });\n        }\n\n        if (missingDependencyNames.Count > 0)\n            throw new ArgumentException(\n                $\"Cannot add module {moduleName} because it has dependencies on other modules that are not present: {string.Join(\", \", missingDependencyNames)}\");\n\n        m_targetData.report.modules.Add(new LinkerToEditorData.ReportData.Module\n        {\n            name = moduleName,\n            dependencies = moduleDependencies\n        });\n    }\n\n    public bool IsModuleIncluded(string moduleName) => m_targetData.report.modules.Find(m => m.name == moduleName) != null;\n}\n","sourceCodeStart":45,"sourceCodeEnd":75,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Modules/PostStrippingModuleAdder.cs#L45-L75","documentation":"Thrown by PostStrippingModuleAdder when the module to be added has dependencies on other modules that are not present in the target report's module list. The editor refuses to add a module whose dependency graph is unsatisfied.","triggerScenarios":"Calling AddModule for a module whose ModuleMetadata.GetModuleDependencies returns names not found via IsModuleIncluded — i.e., required sibling modules were never added or were stripped.","commonSituations":"Adding a module in isolation without its transitive dependencies. Dependencies stripped during the build and not re-added. Module metadata changed across Unity versions.","solutions":["Add all missing dependency modules first (the names are listed in the exception message).","Resolve the full dependency closure via ModuleMetadata.GetModuleDependencies transitively before adding.","Verify module metadata files match the installed Unity version."],"exampleFix":"// before\nAddModule(\"Physics2D\"); // throws if its deps are missing\n// after: add dependencies first\nforeach (var dep in ModuleMetadata.GetModuleDependencies(\"Physics2D\"))\n    if (!IsModuleIncluded(dep)) AddModule(dep);\nAddModule(\"Physics2D\");","handlingStrategy":"validation","validationCode":"var missing = ModuleMetadata.GetModuleDependencies(moduleName)\n    .Where(d => !IsModuleIncluded(d)).ToList();\nif (!missing.Any()) AddModule(moduleName);","typeGuard":null,"tryCatchPattern":"try { AddModule(name); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"dependencies on other modules\"))\n{ /* parse listed deps, add them first */ }","preventionTips":["Resolve the full dependency closure before adding.","Use ModuleMetadata.GetModuleDependencies for the canonical list.","Match module metadata to the Unity version."],"tags":["unity","modules","dependencies","stripping"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}