سؤال

I am receiving this error:

Uncaught exception 'InvalidArgumentException' with message 'Constant name is expected.

While running php bin/magento setup:upgrade in command line.

i got this http://awesomescreenshot.com/0535zi4648 error.

هل كانت مفيدة؟

المحلول

I think some problem in your etc folder. check all xml files. Constant name should be in CAPITAL letters. any of your constant remain in small letters. check it and correct it. Hope this will solve your Problem.

نصائح أخرى

In order to help you debug what's going on, I would suggest to temporary edit the file

vendor/magento/framework/Data/Argument/Interpreter/Constant.php

From this...

public function evaluate(array $data) {
    if(!isset($data['value']) || !defined($data['value'])) {
        throw new \InvalidArgumentException('Constant name is expected.');
    }
    return constant($data['value']);
}

To this...

public function evaluate(array $data) {
    if(!isset($data['value']) || !defined($data['value'])) {
        print_r($data);exit;                                                    // <<<<<<<<<<<<
        throw new \InvalidArgumentException('Constant name is expected.');
    }
    return constant($data['value']);
}

Thereby you will be notified of which class / constant is causing you the error :

enter image description here

Hope it could help someone else ;-) See ya

In a case when your extension is in app/code folder you will get this error if your folder name is different than module name after Magento_ in module.xml

for an example: if your module name is Magento_MyGreatModule your folder name must be MyGreatModule.

Like already stated in the previous answers, this is most likely because some error in one of your configuration files. For instance, this error is triggered when you do the following without having a class that declares the constant (notice the ::CODE declaration):

<!-- etc/di.xml -->
<virtualType name="ExamplePaymentGatewayConfig" type="Magento\Payment\Gateway\Config\Config">
  <arguments>
    <argument name="methodCode" xsi:type="const">\Company\Example\Model\Ui\ConfigProvider::CODE</argument>
  </arguments>
</virtualType> 

In my case the const CODE has wrong name and temporary modify the file

vendor/magento/framework/Data/Argument/Interpreter/Constant.php

Is helped me to find the name of the actual module.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top