puppetlabs/puppet · error · Puppet::Error

Could not find class

Error message

Could not find class %{name} for %{node}

What it means

evaluate_classes resolves each requested class name through environment.known_resource_types.find_hostclass (the Puppet 3.x/autoloader path); a miss raises Puppet::Error 'Could not find class X for node'. Resolution happens before instantiation, so the class must already be loadable from the environment's modulepath.

Solutions

  1. Check the module is present in the compiling environment's modulepath (puppet module list / puppet config print modulepath)
  2. Verify autoloader layout: foo::bar must live in foo/manifests/bar.pp and define foo::bar
  3. Fix class name spelling and casing to match the declared name exactly
  4. Confirm the node resolves to the environment that actually contains the module

Example fix

// before: roles/manifests/web_server.pp defines roles::web_server
include roles::webserver

// after
include roles::web_server
Defensive patterns

Strategy: try-catch

Validate before calling

# API-level pre-check: does the environment resolve the class?
env.known_resource_types.find_hostclass(class_name) or raise LoadError, "class #{class_name} not loadable"

Try / catch

begin
  compiler.compile
rescue Puppet::Error => e
  if (m = e.message.match(/Could not find class (\S+) for /))
    missing << m[1]
  end
  raise
end

Prevention

When it happens

Trigger: include profile::web when the profile module is not in the environment's modulepath; foo::bar expected in foo/manifests/bar.pp but the file is named differently; class name casing mismatch; wrong environment (module exists in production, node compiles in test).

Common situations: Module not installed or renamed; environment mismatch between agent and code; Puppet 4+ strict module layout violations; typos in class names; rspec-puppet tests without module fixture metadata.

Related errors


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

Appendix: source

Thrown at lib/puppet/parser/compiler.rb:249

  # Evaluates each specified class in turn. If there are any classes that
  # can't be found, an error is raised. This method really just creates resource objects
  # that point back to the classes, and then the resources are themselves
  # evaluated later in the process.
  #
  def evaluate_classes(classes, scope, lazy_evaluate = true)
    raise Puppet::DevError, _("No source for scope passed to evaluate_classes") unless scope.source

    class_parameters = nil
    # if we are a param class, save the classes hash
    # and transform classes to be the keys
    if classes.instance_of?(Hash)
      class_parameters = classes
      classes = classes.keys
    end

    hostclasses = classes.collect do |name|
      environment.known_resource_types.find_hostclass(name) or raise Puppet::Error, _("Could not find class %{name} for %{node}") % { name: name, node: node.name }
    end

    if class_parameters
      resources = ensure_classes_with_parameters(scope, hostclasses, class_parameters)
      unless lazy_evaluate
        resources.each(&:evaluate)
      end

      resources
    else
      already_included, newly_included = ensure_classes_without_parameters(scope, hostclasses)
      unless lazy_evaluate
        newly_included.each(&:evaluate)
      end

      already_included + newly_included
    end
  end

View on GitHub (pinned to e227c27540)