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
andgenerated/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.
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->create('Magento\\Framewo...')
#1 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(160): Magento\Framework\ObjectManager\ObjectManager->get('Magento\\Framewo...')
#2 /Users/martins/www/my-magento2-dir/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(246): Magento\Framework\ObjectManager\Factory\AbstractFactory->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
- Magento Docs: General CLI Installation (where it says Magento doesn't prompt to use setup:di:compile in developer mode)
- Github - Issue solving the "problem" to ask running setup:di:compile in dev mode
- When you should run di:compile (blog post from Cadence Labs)