2

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)
  • Exactly my question as well in Magento 2.3, which is annoying. Any insights? – Rinto George May 31 at 6:23
0

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

| improve this answer | |
0

The Command: php bin/magento setup:di:compile

This command does not need to be run when the app is in Developer mode. Magento uses automatic code generation when the app is in this mode, and if it can’t find a generated class it creates it on the fly.

In Production mode, this command should run each time the changes have been made especially related to PHP.

Resource and more info: https://support.serverguy.com/portal/kb/articles/magento-2-bin-magento-setup-di-compile

| improve this answer | |
  • That's what the documentation says, but as you can see in the example in the question, it's not what happens. The error only goes away when I run the command, even in developer mode. – Ricardo Martins Mar 14 at 7:24

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.