Magento 2 – Why Can’t Switch Back to Default Mode?

command linedeveloper-modemagento-2.0magento-2.0.4magento2

So I have switched to the developer mode while developing on a Magento 2 project using the following command:

php bin/magento deploy:mode:set developer

All good, I got this message and I developed the website fine:

Current application mode: developer.

For some reasons, I wanted to go back to the default mode just to check the behavior of the website in this mode. No specific reasons to be honest, I just wanted to switch back to this mode.

So I ran the following command:

php bin/magento deploy:mode:set default

But I got this weird error with no further explanations:

Cannot switch into given mode "default"

I checked the following file that handles the mode settings Magento/Deploy/Console/Command/SetModeCommand.php and here's what I've found:

switch($toMode) {
    case State::MODE_DEVELOPER:
        $modeController->enableDeveloperMode();
        break;
    case State::MODE_PRODUCTION:
        if ($skipCompilation) {
            $modeController->enableProductionModeMinimal();
        } else {
            $modeController->enableProductionMode();
        }
        break;
    default:
        throw new LocalizedException(__('Cannot switch into given mode "%1"', $toMode));
}

How weird is that, Magento 2 is shipped in default mode but you can't switch back to that specific mode. What's the reason behind this ?

Edit: for those interested I ended up creating an issue on github: https://github.com/magento/magento2/issues/4292

Best Answer

The default mode is neither here nor there.

mode overview

The Magento team really wants you to use either Production Mode on your live site or Developer Mode during Development. The reason why Default Mode exists is to have something that would at least run reasonably when deployed directly from the downloaded code without further intervention.

By running php bin/magento deploy:mode:set you have identified yourself as capable and not needing the default mode. As there is no reason needing to go back to default mode Magento did not provide a way for you to do so.