puppetlabs/puppet · error · Puppet::ModuleTool::Errors::ModuleIsRequiredError

Could not uninstall '%{module_name}'; installed modules stil

Error message

Could not uninstall '%{module_name}'; installed modules still depend upon it

What it means

Raised by Puppet::ModuleTool::Applications::Uninstaller as Puppet::ModuleTool::Errors::ModuleIsRequiredError (subclass of UninstallError) when other installed modules declare the target as a dependency in their metadata.json. The uninstaller checks mod.required_by and, unless --force is given, refuses to remove a module that would break its dependents. The error's multiline output lists exactly which modules require it.

Source

Thrown at lib/puppet/module_tool/applications/uninstaller.rb:112

          raise _("Either the `--ignore_changes` or `--force` argument must be specified to uninstall modules when running in FIPS mode.") if Puppet.runtime[:facter].value(:fips_enabled)

          changes = begin
            Puppet::ModuleTool::Applications::Checksummer.run(mod.path)
          rescue ArgumentError
            []
          end

          if mod.has_metadata? && !changes.empty?
            raise LocalChangesError,
                  :action => :uninstall,
                  :module_name => (mod.forge_name || mod.name).tr('/', '-'),
                  :requested_version => @options[:version],
                  :installed_version => mod.version
          end
        end

        if !@options[:force] && !mod.required_by.empty?
          raise ModuleIsRequiredError,
                :module_name => (mod.forge_name || mod.name).tr('/', '-'),
                :required_by => mod.required_by,
                :requested_version => @options[:version],
                :installed_version => mod.version
        end
      end
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Uninstall the dependent modules first (the error message lists them via required_by), then uninstall this one
  2. If the dependents' declarations are stale, edit their metadata.json to drop the dependency, then uninstall
  3. Override deliberately with `puppet module uninstall <name> --force` (note: --force also skips the local-changes check)
  4. Map the tree first with `puppet module list --tree` to see which modules pull it in

Example fix

# before
$ puppet module uninstall puppetlabs-stdlib
# Error: Could not uninstall 'puppetlabs-stdlib'; installed modules still depend upon it

# after
$ puppet module uninstall puppetlabs-apache
$ puppet module uninstall puppetlabs-stdlib
Defensive patterns

Strategy: validation

Validate before calling

mod = env.modules.find { |m| (m.forge_name || m.name).tr('/', '-') == name }
unless mod.nil? || mod.required_by.empty?
  dependents = mod.required_by.map { |r| r['name'] }.join(', ')
  abort "#{name} is required by: #{dependents} — uninstall those first or pass --force"
end

Try / catch

result = Puppet::ModuleTool::Applications::Uninstaller.run(name, options)
if (m = result[:error] && result[:error][:oneline] =~ /still depend upon/)
  dependents = mod.required_by.map { |r| r['name'] }
  dependents.each { |d| Puppet::ModuleTool::Applications::Uninstaller.run(d, options) }
  Puppet::ModuleTool::Applications::Uninstaller.run(name, options)
end

Prevention

When it happens

Trigger: Running `puppet module uninstall <name>` without --force when at least one other module in the environment's module path lists <name> in the dependencies of its metadata.json, e.g. uninstalling puppetlabs-stdlib while puppetlabs-apache requires it.

Common situations: Trying to remove widely shared modules like stdlib, concat, or translate; stale metadata.json of hand-copied modules still referencing the module; cleaning up after a refactoring that removed the last real consumer but left the dependency declaration behind.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/9983cbb7baf013e6. Report an issue: GitHub.