I wrote a custom shipping module for Magento 2.0 that adds an LTL/Fright option. It worked in Magento 2.0.7, and I was recently testing 2.1.7. It appears all of my other (self authored) modules work, but my Shipping module does not.

After adding an item to the cart, and going to http://localhost/checkout/cart I get the following error:

Exception #0 (ReflectionException): Class Comstar\Tli\Model\Carrier does not exist
#0 D:\Web\html\vendor\magento\framework\Code\Reader\ClassReader.php(19): ReflectionClass->__construct('Comstar\\Tli\\Mod...')
#1 D:\Web\html\vendor\magento\framework\ObjectManager\Definition\Runtime.php(44): Magento\Framework\Code\Reader\ClassReader->getConstructor('Comstar\\Tli\\Mod...')
#2 D:\Web\html\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php(71): Magento\Framework\ObjectManager\Definition\Runtime->getParameters('Comstar\\Tli\\Mod...')
#3 D:\Web\html\vendor\magento\framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Comstar\\Tli\\Mod...', Array)
#4 D:\Web\html\vendor\magento\module-shipping\Model\CarrierFactory.php(74): Magento\Framework\ObjectManager\ObjectManager->create('Comstar\\Tli\\Mod...')
#5 D:\Web\html\vendor\magento\module-shipping\Model\Config.php(65): Magento\Shipping\Model\CarrierFactory->create('tli', NULL)
#6 D:\Web\html\vendor\magento\module-checkout\Model\DefaultConfigProvider.php(590): Magento\Shipping\Model\Config->getActiveCarriers()
#7 D:\Web\html\vendor\magento\module-checkout\Model\DefaultConfigProvider.php(292): Magento\Checkout\Model\DefaultConfigProvider->getActiveCarriers()
#8 D:\Web\html\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Checkout\Model\DefaultConfigProvider->getConfig()
#9 D:\Web\html\var\generation\Magento\Checkout\Model\DefaultConfigProvider\Interceptor.php(26): Magento\Checkout\Model\DefaultConfigProvider\Interceptor->___callPlugins('getConfig', Array, Array)
#10 D:\Web\html\vendor\magento\module-checkout\Model\CompositeConfigProvider.php(32): Magento\Checkout\Model\DefaultConfigProvider\Interceptor->getConfig()
#11 D:\Web\html\vendor\magento\module-checkout\Block\Cart\Shipping.php(54): Magento\Checkout\Model\CompositeConfigProvider->getConfig()
#12 D:\Web\html\vendor\magento\module-checkout\view\frontend\templates\cart\shipping.phtml(28): Magento\Checkout\Block\Cart\Shipping->getCheckoutConfig()
.... (stack trace continues to 95 lines)


namespace Comstar\Tli\Model;

[... class imports ...]

class Carrier extends AbstractCarrier implements CarrierInterface
    [... var declarations ...]

    public function __construct([... DI ...])
        parent::__construct($scopeConfig, $errorFactory, $log, $data)


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
                <name>Comstar LTL</name>
                <specificerrmsg>There are no LTL Quotes available for this shipment.</specificerrmsg>

The Class Comstar\Tli\Model\Carrier clearly exists, and as I said, this module worked in 2.0.7. I did a quick review of Magento_Ups to see if anything major changed in the way shipping modules are loaded, but it doesn't appear to be built any differently.

I am running on WAMP 3.0.9, PHP 7.0.21. I updated from 2.0.7 to 2.1.7 by deleting the /vendor/ folder and copying all 2.1.7 files into the Magento 2 root.

Why isn't Magento 2.1 able to find my Class?


7 Answers 7


I my case,

enter image description here

I had actually a syntax error in the constructor. but it was not shown as usual errors with line number. I ran,

php bin/magento setup:di:compile

It displayed there is a syntax error and showed line number. Then updgrade,

php bin/magento setup:upgrade

and deploy,

php bin/magento setup:static-content:deploy

for developer mode,

php bin/magento setup:static-content:deploy -f

It may be helpful.

  • 3
    Yes, setup:di:compile is the key. Thanks! Commented Sep 28, 2018 at 8:49

You can try to use



Also, try to remove var/cache/* var/page_cache/* var/generation/*

and run



  • I'm in developer mode with the cache disabled. I ran setup:di:compile anyway, and it only moves the error to the PHP log and changes the stack trace a little.
    – andyjv
    Commented Jul 21, 2017 at 15:38

Turns out on this particular file, I had opened with a <? tag instead of a <?php tag. I'm not sure if it was the newer version of WAMP or PHP that triggered that sensitivity, but using <?php fixed the problem!

  • 2
    old post but - worth noting php.ini setting allow_short_open_tags (or something similar) - setting that to yes allows use of <?
    – treyBake
    Commented Nov 8, 2017 at 14:22

I solve this, Hope some one will be get help

  • cd magento2.3.x

    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +

    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +

    chown -R :www-data .

    chmod u+x bin/magento


Log into your server and cd into Magento's root directory and run:

php bin/magento setup:di:compile

I found that it might be a result of PHP Strict type:


I removed this in my custom module, In case this helps others.


Check the spelling of the class used in dependency injection.

In my case, the error occurred when I had the following class in DI:


instead of


Note the difference between "Mode" and "Model".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.