Hello there!
I created a module for Magento2 and now need to include some 3d-party vendors.
I've read multiple posts about achieving this. I have tried these, but I can't get it to work correctly.
Adding the autoload.php to the composer.json of the modul
"autoload": { "files": [ "registration.php", "thrdParty/vendor/autoload.php" ] }
Or adding the autoload.php directly to the registration.php
require_once "thrdParty/vendor/autoload.php";
Both methods work in so far that I can use said vendors in my module. However, when I run the compile command, I get an error "Interface ... not found#0".
php bin/magento setup:di:compile
I guess I could add the vendors to the Magento2 composer.json file, but that doesn't seem like a good practice.
I would be grateful for any help/insights!
Hello @adid01nete33ad
Third-party libraries often require proper autoloading configurations. Magento 2 uses Composer for autoloading, and missing or incorrect configuration can lead to errors.
Composer Integration: Add the library to your composer.json file.
{ "require": { "vendor/package-name": "^1.0" } }
Custom Autoload: If the library isn't available via Composer, you can use autoload to include it manually.
"autoload": { "files": [ "path/to/your/vendor/library.php" ] }
Vendor Directory: Place the library in your module's lib directory and load it in your module's registration.php or helper file:
require_once BP . '/app/code/Vendor/Module/lib/library.php';
Hope it helps !
If you find our reply helpful, please give us kudos.
A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.
WebDesk Solution Support Team
Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Thank You,
WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Location: 150 King St. W. Toronto, ON M5H 1J9