digitalmarketing and seo
Slide 1

We Designed for

Web Development
Image is not available

In the dynamic landscape of digital presence, harnessing the power of effective web development is paramount. At TAG VIBE....

Slide 2

We Designed

App Development
Image is not available

In today's mobile-centric world, having a mobile app is essential for reaching and engaging with your
audience....

Slide 3

We Designed

Digital Marketing & Search Engine Optimization
Image is not available

we great to do digital marketing and search engine optimization work as per google rule and regulation....

previous arrowprevious arrow
next arrownext arrow

How to fix the “AREA CODE NOT SET” issue?

Spread the love

Magento 2 Area code not set

As a Magento developer we are facing lot of issue which is common while developing and customizing a module. Today we are going to discuss about How to fix the “Area code not set” issue. This error occurs mainly from four reason CRON, CLI , Setup Scripts and use of session in wrong area and it will pop up when you are either compiling or running setup upgrade command. In both of the cases, it tries to create an object using the constructor of your classes but couldn’t find the area code and it fails to load.

WHAT IS AREA CODE IN MAGENTO 2?

Magento uses area codes to define the entry point to application to load given a specific request context. There are seven distinct ‘areas’ of the system, each with their own area code:

  1. global
  2. doc
  3. crontab
  4. frontend
  5. adminhtml
  6. webapi_rest
  7. webapi_soap

When setting the session for customer or Order we should define the area.

It’s Fixed related to this :

  1. Magento 2.2 area code not set: area code must be set before starting a session.
  2. upgrading data.. area code not set: area code must be set before starting a session.
  3. Magento 2 setup upgrade import failed: area code is not set
  4. import failed: area code not set: area code must be set before starting a session.
  5. Magento 2 area code admin does not exist
  6. processing configurations data from configuration file… import failed: area code is not set
  7. import failed: area code is not set magento2
  8. area code “” does not exist Magento 2

For Example:

We are creating a plugin or overriding a method of core class in custom class and we have injected Magento core session manager and customer session in custom class constructor.

For overriding the existing core class method we are using preference in di.xml and keep in global onside our custom module. when we run complile and upgrade we will get “AREA CODE NOT SET” issue.

Solution:

To resolve this issue we should keep the di.xml in frontend area as we are using customer session in our class. Likewise if you are using Magento Backend session in your custom class you should keep the di.xml in adminhtml area.

Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

Scroll to Top