The configuration for the "modules" component must contain a "class" element
<p>I have define a module named `admin' in yii2.
I have registered this module in  web.php config file.
But when I try to access this I face with an error.</p>

<p>here is my web.php</p>

<pre><code>&lt;?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' =&gt; 'basic',
    'basePath' =&gt; dirname(__DIR__),
    'language'=&gt;'fa_ir',
    'bootstrap' =&gt; ['log'],
    'components' =&gt; [
        'request' =&gt; [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' =&gt; 'SiMhYyhP2MZ_BAi321KfDHFk5uleQFa9',
        ],
        'jdate' =&gt; [
            'class' =&gt; 'jDate\DateTime'
        ],
        'cache' =&gt; [
            'class' =&gt; 'yii\caching\FileCache',
        ],
        'user' =&gt; [
            'identityClass' =&gt; 'app\models\User',
            'enableAutoLogin' =&gt; true,
        ],
        'errorHandler' =&gt; [
            'errorAction' =&gt; 'site/error',
        ],
        'modules' =&gt; [
            'admin' =&gt; [
                'class' =&gt; 'app\modules\admin\Module',
            ],
        ],
        'mailer' =&gt; [
            'class' =&gt; 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' =&gt; false,
            'transport' =&gt; [
                'class' =&gt; 'Swift_SmtpTransport',
                'host' =&gt; 'smtp.gmail.com',
                'username' =&gt; 'pishevaris@gmail.com',
                'password' =&gt; 'bhtk1368',
                'port' =&gt; '587',
                'encryption' =&gt; 'tls',
            ],
        ],
        'log' =&gt; [
            'traceLevel' =&gt; YII_DEBUG ? 3 : 0,
            'targets' =&gt; [
                [
                    'class' =&gt; 'yii\log\FileTarget',
                    'levels' =&gt; ['error', 'warning'],
                ],
            ],
        ],
        'urlManager' =&gt; [
            'class' =&gt; 'yii\web\UrlManager',
            // Disable index.php
            'showScriptName' =&gt; false,
            // Disable r= routes
            'enablePrettyUrl' =&gt; true,
            'rules' =&gt; array(
                '&lt;controller:\w+&gt;/&lt;id:\d+&gt;' =&gt; '&lt;controller&gt;/view',
                '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;' =&gt; '&lt;controller&gt;/&lt;action&gt;',
                '&lt;controller:\w+&gt;/&lt;action:\w+&gt;' =&gt; '&lt;controller&gt;/&lt;action&gt;',
            ),
        ],
        'db' =&gt; require(__DIR__ . '/db.php'),
    ],
    'params' =&gt; $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' =&gt; 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' =&gt; 'yii\gii\Module',
    ];
}

return $config;
</code></pre>

<p>here is my Module class:</p>

<pre><code>&lt;?php

namespace app\modules\admin;

class Module extends \yii\base\Module
{
    public $controllerNamespace = 'app\modules\admin\controllers';

    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
}
</code></pre>

<p>but when I try to access mysite/admin/default/index I face <code>The configuration for the "modules" component must contain a "class" element</code> error</p>