0

We are launching a Magento 2.4.2 site, and finding that the site will sometimes load all of its Javascript components and dependencies properly, but sometimes fails to load on the custom component. In which case a knockout template is not displayed and the console log shows an error message such as "[ERROR] Failed to load the "Vendor_ModuleName/js/view/minitest" component.". If you reload the page, this error may disappear.

This custom component has very similar functionality to the minicart.

My files:

default.xml

    <block class="Vendor\ModuleName\Block\Test\Sidebar" name="minitest" after="minitest" template="test/minitest.phtml">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="types" xsi:type="array"/>
                        <item name="components" xsi:type="array">
                            <item name="miniquote_content" xsi:type="array">
                                <item name="component" xsi:type="string">Vendor_ModuleName/js/view/minitest</item>
                        ...
                 </arguments>
     </block>

minitest.phtml

.....
<script type="text/x-magento-init">
        {
            "[data-block='minitest']": {
                "Magento_Ui/js/core/app": <?php echo $block->getJsLayout(); ?>
            },
            "*": {
                "Magento_Ui/js/block-loader": "<?php echo $block->escapeHtml($block->getViewFileUrl('images/loader-1.gif')); ?>"
            }
        }
 </script>

1 Answer 1

0

I don't know why, but it helped me to solve this problem:

requirejs-config.js

var config = {
    shim: {
        'Vendor_ModuleName/js/view/minitest': {
            deps: ['Magento_Checkout/js/view/minicart']
        }
    }
};

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.