InvalidArgumentException… Class not Found in Custom Module

Here is the simplified error:

InvalidArgumentException: Class “DrupalprepcartControllerPrepCartController” does not exist. in DrupalCoreDependencyInjectionClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

Full Stack Trace:

The website encountered an unexpected error. Please try again later.
InvalidArgumentException: Class “DrupalprepcartControllerPrepCartController” does not exist. in DrupalCoreDependencyInjectionClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).
DrupalCoreControllerControllerResolver->createController(‘DrupalprepcartControllerPrepCartController::content’) (Line: 74)
DrupalCoreControllerControllerResolver->getControllerFromDefinition(‘DrupalprepcartControllerPrepCartController::content’, ‘/cart’) (Line: 91)
DrupalCoreControllerControllerResolver->getController(Object) (Line: 132)
SymfonyComponentHttpKernelHttpKernel->handleRaw(Object, 1) (Line: 64)
SymfonyComponentHttpKernelHttpKernel->handle(Object, 1, 1) (Line: 57)
DrupalCoreStackMiddlewareSession->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareKernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupalpage_cacheStackMiddlewarePageCache->pass(Object, 1, 1) (Line: 77)
Drupalpage_cacheStackMiddlewarePageCache->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
StackStackedHttpKernel->handle(Object, 1, 1) (Line: 628)
DrupalCoreDrupalKernel->handle(Object) (Line: 19)

Relevant information: Drupal Core 8.1.8 (I know 8.2 is out but this shouldn’t matter I believe – we are pinned to this version due to Lightning)

And here is the relevant files involved:

PrepCartController.php

<?php
/**
 * @file
 * Contains DrupalprepcartControllerPrepCartController.
 */
namespace DrupalprepcartController;
use DrupalCoreControllerControllerBase;
class PrepCartController extends ControllerBase {
  public function content() {
    return array(
      '#type' => 'markup',
      '#markup' => $this->t('Hello, IHM!'),
    );
  }
};

To make life easier this is the directory structure:

drwxr-xr-x   170B Oct 18 07:05 ./
-rw-r--r--   222B Oct 18 06:36 ./prepcart.info.yml
-rw-r--r--   195B Oct 18 07:05 ./prepcart.routing.yml
drwxr-xr-x   102B Oct 18 06:53 ./src/
drwxr-xr-x   102B Oct 18 06:54 ./src/Controller/
-rw-r--r--   349B Oct 18 06:54 ./src/Controller/PrepCartController.php

For some reason the module won’t show on the modules page but I can interact with it fine on the CLI using drush?

Trust me when I say I have been ALL over Google and Stack for this. Major love to whomever can help me here.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

InvalidArgumentException… Class not Found in Custom Module

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.