1

I recently upgraded a Magento instance from version 2.4.5-p4 to 2.4.5-p5 . Its running on PHP 7.4.9 . Its a AWS/bitnami instance.

The upgrade seems succesful (no errors shown in front end or admin, when the version is checked it show 2.4.5-p5 .

However, the setup:di:compile command gets interrupted with following errors.

syntax error, unexpected '|', expecting ';' or '{'#0 /opt/bitnami/magento/vendor                                                                             /composer/ClassLoader.php(428): Composer\Autoload\{closure}()
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#2 [internal function]: spl_autoload_call()
#3 /opt/bitnami/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesSca                                                                             nner.php(134): class_exists()
#4 /opt/bitnami/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesSca                                                                             nner.php(117): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->includeClass(                                                                             )
#5 /opt/bitnami/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesSca                                                                             nner.php(87): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->extract()
#6 /opt/bitnami/magento/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Rep                                                                             ositoryGenerator.php(61): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->ge                                                                             tList()
#7 /opt/bitnami/magento/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(5                                                                             6): Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator->doOperation(                                                                             )
#8 /opt/bitnami/magento/setup/src/Magento/Setup/Console/Command/DiCompileCommand                                                                             .php(216): Magento\Setup\Module\Di\App\Task\Manager->process()
#9 /opt/bitnami/magento/vendor/symfony/console/Command/Command.php(255): Magento                                                                             \Setup\Console\Command\DiCompileCommand->execute()
#10 /opt/bitnami/magento/vendor/symfony/console/Application.php(1021): Symfony\C                                                                             omponent\Console\Command\Command->run()
#11 /opt/bitnami/magento/vendor/symfony/console/Application.php(275): Symfony\Co                                                                             mponent\Console\Application->doRunCommand()
#12 /opt/bitnami/magento/vendor/magento/framework/Console/Cli.php(116): Symfony\                                                                             Component\Console\Application->doRun()
#13 /opt/bitnami/magento/vendor/symfony/console/Application.php(149): Magento\Fr                                                                             amework\Console\Cli->doRun()
#14 /opt/bitnami/magento/bin/magento(23): Symfony\Component\Console\Application-                                                                             >run()
#15 {main}

By putting a echo in composer/ClassLoader.php error location, I found that this error is occuring when /opt/bitnami/magento/vendor/composer/../paypal/module-braintree-core/Gateway/Com mand/GetPaymentNonceCommand.php is processed.

If you have encountered same or a similar issue, I do highly appreciate if you could please guide me to resolve it.

Thanks and Best Regards

Indunil

2 Answers 2

0

You need PHP version 8.1 because of your Magento version 2.4.5-p3 requirement. If you do not want to upgrade the PHP version, you need to modify the 'paypal/module-braintree-core' and 'paypal/module-braintree-graph-ql' packages. Do not remove these packages as they are required by the Magento system.

Magento 2.4.5-p5 System Requirements: https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/system-requirements.html

We encountered the same issue. In our situation, we had ceased using the Paypal package, and there were no remaining dependencies on that package. To address the problem, we made modifications to the relevant packages and then added them to the composer. Please consider implementing the solution provided below:

Update your repositories content into your composer.json file

"repositories": {
    "local": {
        "type": "path",
        "url": "packages/*/*"
    },
    "magento_repo": {
        "type": "composer",
        "url": "https://repo.magento.com/"
    }
},

magentoRoot/packages/paypal/module-braintree-core

registration.php

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'PayPal_Braintree',
    __DIR__
);

magentoRoot/packages/paypal/module-braintree-core

composer.json

{
    "name": "paypal/module-braintree-core",
    "description": "Fork from the Magento Braintree 2.2.0 module by Gene Commerce for PayPal.",
    "type": "magento2-module",
    "license": "proprietary",
    "version": "4.3.0-p1",
    "require": {
        "braintree/braintree_php": "6.5.1",
        "magento/module-customer": "101.0.*||102.0.*||^103.0.0",
        "magento/module-config": "101.0.*||101.1.*||^101.2.0",
        "magento/module-sales": "101.0.*||102.0.*||^102.1.0||^103",
        "magento/module-directory": "100.2.*||100.3.*||^100.4.0",
        "magento/module-payment": "100.2.*||100.3.*||^100.4.0",
        "magento/module-checkout": "100.2.*||100.3.*||^100.4.0",
        "magento/module-backend": "100.2.*||101.0.*||^102.0.0",
        "magento/module-vault": "101.0.*||101.1.*||^101.2.0",
        "magento/module-catalog": "102.0.*||103.0.*||^104.0.0",
        "magento/module-quote": "101.0.*||101.1.*||^101.2.0",
        "magento/module-paypal": "100.2.*||100.3.*||^101.0.0",
        "magento/module-theme": "100.2.*||101.0.*||^101.1.0",
        "magento/module-ui": "101.0.*||101.1.*||^101.2.0",
        "magento/module-re-captcha-ui": "1.1.*",
        "magento/module-re-captcha-validation-api": "1.1.*",
        "ext-json": "*",
        "ext-simplexml": "*"
    },
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "PayPal\\Braintree\\": ""
        }
    },
    "conflict": {
        "magento/module-braintree": "*",
        "gene/module-braintree": "*"
    }
}

magentoRoot/packages/paypal/module-braintree-core/etc

module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="PayPal_Braintree" setup_version="4.0.3">
        <sequence>
            <module name="Magento_Customer"/>
            <module name="Magento_Config"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Directory"/>
            <module name="Magento_Payment"/>
            <module name="Magento_Checkout"/>
            <module name="Magento_Vault"/>
            <module name="Magento_Catalog"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Paypal"/>
            <module name="Magento_Theme"/>
            <module name="Magento_Ui"/>
        </sequence>
    </module>
</config>

magentoRoot/packages/paypal/module-braintree-graph-ql

registration.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'PayPal_BraintreeGraphQl', __DIR__);

magentoRoot/packages/paypal/module-braintree-graph-ql

composer.json

{
    "name": "paypal/module-braintree-graph-ql",
    "description": "N/A",
    "type": "magento2-module",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "version": "4.3.0",
    "require": {
        "magento/framework": "^102||^103",
        "paypal/module-braintree-core": "^4.1",
        "magento/module-store": "^101",
        "magento/module-quote": "^101",
        "magento/module-quote-graph-ql": "^100"
    },
    "suggest": {
        "magento/module-graph-ql": "^100"
    },
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "PayPal\\BraintreeGraphQl\\": ""
        }
    }
}

magentoRoot/packages/paypal/module-braintree-graph-ql/etc

module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="PayPal_BraintreeGraphQl">
        <sequence>
            <module name="PayPal_Braintree"/>
        </sequence>
    </module>
</config>

Then, please update your composer.lock file using the command below:

composer update --lock

Then, run your Magento command and check the DI compilation.

Note: If Composer does not update your package and the DI compilation still shows an error, then remove your 'generated' folder, remove the 'vendor' folder, and delete the 'composer.lock' file. Once removed, run the 'composer install' command and check it again after running the 'magento setup:upgrade' command.

0

Or you can tmp apply the changes by a composer patch

patches/paypal/braintree_broken_dependency_magento_issue_37877.patch

Index: vendor/paypal/module-braintree-core/Gateway/Command/GetPaymentNonceCommand.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/paypal/module-braintree-core/Gateway/Command/GetPaymentNonceCommand.php b/vendor/paypal/module-braintree-core/Gateway/Command/GetPaymentNonceCommand.php
--- a/vendor/paypal/module-braintree-core/Gateway/Command/GetPaymentNonceCommand.php
+++ b/vendor/paypal/module-braintree-core/Gateway/Command/GetPaymentNonceCommand.php    (date 1703003253261)
@@ -71,7 +71,7 @@
      * @return ArrayResult|ResultInterface|null
      * @throws LocalizedException
      */
-    public function execute(array $commandSubject): ArrayResult|ResultInterface|null
+    public function execute(array $commandSubject)
     {
         $publicHash = $this->subjectReader->readPublicHash($commandSubject);
         $customerId = $this->subjectReader->readCustomerId($commandSubject);

composer.json

{
...
    "require": {
        ...
        "cweagans/composer-patches": "^1.7",
        ...
    },
    
    "extra": {
        ...
        "patches": {
            "paypal/module-braintree-core": {
                "Fixes Magento 2.4.5-p5 Braintree/Paypal broken dependency on PHP7.4": "patches/paypal/braintree_broken_dependency_magento_issue_37877.patch"
            }
        }
    }
}

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.