I've a custom command line module as follows:

namespace Test\MosIntegration\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class FixOrders extends Command
    protected $_helper;
    protected $_state;

    public function __construct(
        \Test\MosIntegration\Helper\Data $helper,
        \Magento\Framework\App\State $state
        $this->_helper = $helper;
        $this->_state = $state;

    protected function configure()
        $this->setDescription('Fix missing orders');
            new InputArgument(
                __("Batch Id")


    protected function execute(InputInterface $input, OutputInterface $output)


i've already set "$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);", but when i ran setup:upgrade, the command prompt still show

  Area code is not set

it is very strange because i've 4 others command in another module it works fine, anyone knows what are the problems?

  • did you try with $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
    – S.P
    Commented Jun 13, 2022 at 11:50

1 Answer 1


Might be because of the area try changing for(I've always used admin area for cli command). That being said i'm not sure it will fix your issue.

    try {
    } catch (Exception $e) {
        $output->writeln('<error>' . $e->getMessage() . '</error>');
  • thx for the reply, i found the problem it is the helper problem, i removed the helper injection in contructor than works fine, not sure the reason.
    – hkguile
    Commented Jun 11, 2022 at 16:02

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.