Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception 'yii\base\InvalidParamException' with message 'Invalid path alias: @modules/controllers' #9

Closed
eriweb opened this issue Dec 7, 2017 · 4 comments

Comments

@eriweb
Copy link

eriweb commented Dec 7, 2017

When trying to use the ./craft command I get the this error on a freshly installed RC1 system.

Exception 'yii\base\InvalidParamException' with message 'Invalid path alias: @modules/controllers'

in /home/user/source/vendor/yiisoft/yii2/BaseYii.php:154

Stack trace:
#0 /home/user/source/vendor/yiisoft/yii2/base/Module.php(257): yii\BaseYii::getAlias('@modules/contro...')
#1 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(250): yii\base\Module->getControllerPath()
#2 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(245): yii\console\controllers\HelpController->getModuleCommands(Object(modules\Module))
#3 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(179): yii\console\controllers\HelpController->getModuleCommands(Object(craft\console\Application))
#4 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(191): yii\console\controllers\HelpController->getCommands()
#5 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(286): yii\console\controllers\HelpController->getCommandDescriptions()
#6 /home/user/source/vendor/yiisoft/yii2/console/controllers/HelpController.php(67): yii\console\controllers\HelpController->getDefaultHelp()
#7 [internal function]: yii\console\controllers\HelpController->actionIndex(NULL)
#8 /home/user/source/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /home/user/source/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /home/user/source/vendor/yiisoft/yii2/console/Controller.php(135): yii\base\Controller->runAction('', Array)
#11 /home/user/source/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
#12 /home/user/source/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('', Array)
#13 /home/user/source/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('', Array)
#14 /home/user/source/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#15 /home/user/source/craft(22): yii\base\Application->run()
#16 {main}

If i return an empty array in config/app.php instead of the default it seems to work

return [];

Instead of:

return [
    'modules' => [
        'my-module' => \modules\Module::class,
    ],
    //'bootstrap' => ['my-module'],
];
@brandonkelly
Copy link
Member

Thanks! Fixed now.

@swthate
Copy link

swthate commented Jul 10, 2019

I am getting the same Exception when trying to run ./craft with Craft 3.1.31:

Exception 'yii\base\InvalidArgumentException' with message 'Invalid path alias: @modules/vetscripts/controllers'

in /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/BaseYii.php:154

Stack trace:
#0 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/Module.php(257): yii\BaseYii::getAlias('@modules/vetscr...')
#1 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(246): yii\base\Module->getControllerPath()
#2 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(241): yii\console\controllers\HelpController->getModuleCommands(Object(modules\vetscripts\VetScripts))
#3 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(175): yii\console\controllers\HelpController->getModuleCommands(Object(craft\console\Application))
#4 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(187): yii\console\controllers\HelpController->getCommands()
#5 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(293): yii\console\controllers\HelpController->getCommandDescriptions()
#6 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/controllers/HelpController.php(67): yii\console\controllers\HelpController->getDefaultHelp()
#7 [internal function]: yii\console\controllers\HelpController->actionIndex(NULL)
#8 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('', Array)
#11 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
#12 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('', Array)
#13 /Users/steven/Code/vetscripts/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('', Array)
#14 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('', Array)
#15 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /Users/steven/Code/vetscripts/craft(22): yii\base\Application->run()
#17 {main}

I have a custom Module defined in config/app.php here:

use modules\vetscripts\VetScripts;

return [
    'modules' => [
        'vetscripts' => VetScripts::class
    ],
    'bootstrap' => ['vetscripts'],
];

@swthate
Copy link

swthate commented Jul 10, 2019

I changed

Craft::setAlias('@vetscripts', __DIR__);

to

Craft::setAlias('@modules/vetscripts', $this->getBasePath());
$this->controllerNamespace = 'modules\vetscripts\controllers';

and now it works! Not sure why, but it's working.

Oops!

@bzin
Copy link

bzin commented Jul 22, 2019

@swthate I imagine that this can occur when you do not have the alias set on your Module constructor

Craft::setAlias('@modules/vetscripts', $this->getBasePath());

At least I was having the same issue and this worked for me. I normally use https://pluginfactory.io to generate my modules. This avoids me a lot of trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants