Solved: Type Error Occurred When Creating Object in Magento 2
Ever faced an error in Magento 2 that states:
Type Error Occurred When Creating Object
This error says something is wrong when creating an object. Generally, the reason for this error is when you’ve passed arguments from the calling method but not receive that arguments in the called function.
For instance, I’ve passed four parameters in calling function and receive three arguments in a called function that means one argument is missing. It results in the error Type Error Occurred When Creating Object in Magento 2.
Sometimes, we’ve created that object, but because of the compilation issue, the object is not created in the generator. Generally, I’ve observed that many programmers tend to delete the whole generated folder to overcome this issue.
However, it’s risky to remove that folder every time which may lead to data loss. Therefore, I’ve come up to the solution of this error instead of removing that folder.
Check out the solution here:
Solution for Type Error Occurred When Creating Object in Magento 2
Pass the below commands in your store’s command line:
1 2 3 4 |
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush |
That’s it.
If you have any doubts regarding this error, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Thank You.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
6 Comments
can someone help me with below error:
Type Error occurred when creating object: Magento\PageBuilder\Component\Form\Element\Wysiwyg, array_key_exists(): Argument #2 ($array) must be of type array, null given
Please do check your argument (parameter), it will be array type and pass as null.
HI
I have this error :
https://prnt.sc/gm43HCmtP76a
https://prnt.sc/PlSIxtA1YC3A
after command executed but did not get resolved:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
Hello Anis,
You’ll need to remove the generated folder and run the di:compile command in order to resolve this error
Thank You
I have this error :
Class Meetanshi\Extension\Model\ExtensionFactory does not exist
Class Smartwave\Porto\Controller\Index\Submit\Interceptor generation
error: The requested class did not generate properly, because the ‘ge
nerated’ directory permission is read-only. If — after running the
‘bin/magento setup:di:compile’ CLI command when the ‘generated’ direc
tory permission is set to write — the requested class did not gener
ate properly, then you must add the generated class object to the sig
nature of the related construct method, only.
after command executed :
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Hello Praveen,
Due to the permission issue, you are facing this issue.
Please run the below command:
chmod -R 777 var generated
Thank You