Not sure this is the right question to ask, but I was given this module with the following line:

$areaCode = $this->state->getAreaCode();

Enabling it gives an error when accessing the website (calling the controller):

Magento\Framework\Exception\LocalizedException: Area code is not set in /var/www/html/magento2/vendor/magento/framework/App/State.php:152

Stack trace: #0 /var/www/html/magento2/vendor/[namespace]/[module]/Plugin/Framework/Session/Config.php(53): Magento\Framework\App\State->getAreaCode()

This makes some sense, but since it controls the session, it requests the area code from something on every page. Either this could be from other parts of the module, or Magento 2 itself.

The question is, if it's the module, how do I know where to put setAreaCode() (as per: 'Area code not set' issue in custom CLI commands in Magento 2)? There is a large number of controllers / execute() functions, does every single one of them need a specific area code?

Is it possible that this means that getAreaCode() should not be used, because there might be another module somewhere that doesn't specify the area code?

  • It isn't really clear to me if you're having the problem while executing a cli command or when calling a controller.
    – Rian
    May 29, 2018 at 21:14
  • When calling the controller (this happens on every page load).
    – Ynhockey
    May 30, 2018 at 10:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.