Unity-Technologies/UnityCsReference · error · ArgumentException

Cannot add module {moduleName} because it has dependencies o

Error message

Cannot add module {moduleName} because it has dependencies on other modules that are not present: {string.Join(", ", missingDependencyNames)}

What it means

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.

Source

Thrown at Editor/Mono/Modules/PostStrippingModuleAdder.cs:63

        {
            if (!IsModuleIncluded(dependency))
            {
                missingDependencyNames.Add(dependency);

                //no need to process this entry further as it is missing from the included module list
                continue;
            }

            moduleDependencies.Add(new LinkerToEditorData.ReportData.Dependency
            {
                name = dependency,
                dependencyType = LinkerToEditorData.ReportData.DependencyType.Custom,
                scenes = Array.Empty<string>(),
            });
        }

        if (missingDependencyNames.Count > 0)
            throw new ArgumentException(
                $"Cannot add module {moduleName} because it has dependencies on other modules that are not present: {string.Join(", ", missingDependencyNames)}");

        m_targetData.report.modules.Add(new LinkerToEditorData.ReportData.Module
        {
            name = moduleName,
            dependencies = moduleDependencies
        });
    }

    public bool IsModuleIncluded(string moduleName) => m_targetData.report.modules.Find(m => m.name == moduleName) != null;
}

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Add all missing dependency modules first (the names are listed in the exception message).
  2. Resolve the full dependency closure via ModuleMetadata.GetModuleDependencies transitively before adding.
  3. Verify module metadata files match the installed Unity version.

Example fix

// before
AddModule("Physics2D"); // throws if its deps are missing
// after: add dependencies first
foreach (var dep in ModuleMetadata.GetModuleDependencies("Physics2D"))
    if (!IsModuleIncluded(dep)) AddModule(dep);
AddModule("Physics2D");
Defensive patterns

Strategy: validation

Validate before calling

var missing = ModuleMetadata.GetModuleDependencies(moduleName)
    .Where(d => !IsModuleIncluded(d)).ToList();
if (!missing.Any()) AddModule(moduleName);

Try / catch

try { AddModule(name); }
catch (ArgumentException ex) when (ex.Message.Contains("dependencies on other modules"))
{ /* parse listed deps, add them first */ }

Prevention

When it happens

Trigger: 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.

Common situations: Adding a module in isolation without its transitive dependencies. Dependencies stripped during the build and not re-added. Module metadata changed across Unity versions.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/0782628415e3b3c4. Report an issue: GitHub.