Home > front end >  setup-install magento 2. Type Error occurred when creating object
setup-install magento 2. Type Error occurred when creating object

Time:10-14

I'm having a problem when I install new Magento 2 on my ubuntu. I got an error when I run the command:

sudo bin/magento setup:install 
--admin-firstname="zzz" 
--admin-lastname="zzz" 
--admin-email="[email protected]" 
--admin-user="admin" 
--admin-password="admin123" 
--db-name="zzzdb" 
--db-user="root" 
--db-password=""

Error: Type Error occurred when creating object: Magento\Framework\Stdlib\DateTime\DateTime

I've consulted the solutions but it seems to be creating a new project, not installing. And I tried rm -rf generated/, chmod -R 777 generated/. But it doesn't work =((

Thanks for any answers.

CodePudding user response:

Type Error means that Object Manager can't instantiate given object due to invalid parameters. The class \Magento\Framework\Stdlib\DateTime\DateTime has a dependency on TimezoneInterface

public function __construct(TimezoneInterface $localeDate)

Which is implemented by Magento\Framework\Stdlib\DateTime\Timezone which then depends on Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory that requires PHP-intl extension. (in the constructor instantiates IntlDateFormatter)

$formatter = new \IntlDateFormatter(
    $locale,
    $dateStyle,
    $timeStyle,
    $timeZone
);

My guess is that you haven't installed intl extension for PHP. https://www.php.net/manual/en/intl.installation.php

You can get more verbose input by providing -vvv as the command argument.

CodePudding user response:

That is very simple, since \DateTime object always contains a timezone, it is possible to translate it into UTC at any time. As you see, it does call internally \Magento\Framework\Stdlib\DateTime to convert time into a text representation.

Ideally, as with any other modern PHP ORM, you should be able to specify the \DateTime object, and the rest of how it is stored should be processed by the library itself. So, it's very well known that during installation, the PHP intl extension is missing.

Hope it will help you.

  • Related