Quick Intro

I'm working on a payment module and using Magento 2.3.2 (irrelevant). As stated in many places, we don't need to run setup:di:compile when in developer mode (which is my scenario).

As we know, once you run it for the first time, generated/code and generated/metadata folders are created and Magento runs in "compiled" mode instead (\Magento\Framework\App\EnvironmentFactory::getMode).

However, after deleting these folders, we should get it normal behaviour, and that's what I did.

The problem

After updating this payment module and going to checkout (/checkout) I always get an ajax error apparently related to dependency injection. checkout page

The error is visible in the html source as follows:

    <script type="text/x-magento-init">
            "#checkout": {
                "Magento_Ui/js/core/app": <br />
<b>Fatal error</b>:  Uncaught Error: Cannot instantiate abstract class Magento\Framework\Model\ResourceModel\AbstractResource in /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50
Stack trace:
#0 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer-&gt;create('Magento\\Framewo...')
#1 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): Magento\Framework\ObjectManager\ObjectManager-&gt;get('Magento\\Framewo...')
#2 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): Magento\Framework\ObjectManager\Factory\AbstractFactory-&gt;resolveArgument(Array, 'Magento\\Framewo...', NULL, 'resource', 'RicardoMartins\\...')
#3 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManage in <b>/Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php</b> on line <b>50</b><br />

Full stack trace available here

Even after setup:upgrade, cache:flush, cache:clean, manual cleanup on common folders, etc, nothing works until I run a setup:di:compile.

Update: When submitting my module to Magento Marketplace, the QA review got the same problem on Magento 2.2.9 (doesn't happen on 2.3.x). But in 2.2.9 even by running setup:di:compile doesn't fix the issue. The problem in this particular case was with the constructor params (see the changes). However, the question still remains for newer versions.

The question

So the question is: am I doing something wrong, or despite the documentation and blog posts about this, we still rely on setup:di:compile even in developer mode?

Additional links and references

  1. Magento Docs: General CLI Installation (where it says Magento doesn't prompt to use setup:di:compile in developer mode)
  2. Github - Issue solving the "problem" to ask running setup:di:compile in dev mode
  3. When you should run di:compile (blog post from Cadence Labs)

It's not mandatory to run setup:di:compile command everytime but if you have done any code change specially with factory methods ,proxy, add plugins or any code compilation then you must need to run this command.

Please Review reference like.

Getting Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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