No base path provided

I am running some console command to generate static page using layout file where layout is using basePath is used as following way

<?= $this->inlineScript()


The given above code is working perfectly fine while request served using web browser. But when I try to run console command this will throw me an error.

The application has thrown an exception!

No base path provided

I am using following code at Module.php file

    public function getServiceConfig()
    return [
        'initializers' => [
            function ($instance, $services) {
                if (! Console::isConsole()) {
                if (! $instance instanceof HelperPluginManager) {
                $instance->setFactory('basePath', function ($sm) use ($services) {
                    $config = $services->get('Config');
                    $config = $config['view_manager'];
                    $basePathHelper = new ViewHelper\BasePath();
                    $basePath = '/';
                    if (isset($config['base_path'])) {
                        $basePath = $config['base_path'];
                    return $basePathHelper;

I suspect you are using the (deprecated) component laminas-console.

Try the following:

And everything should work because laminas-mvc-console adds ConsoleViewHelperManagerDelegatorFactory as delegator for the view helper plugin manager.