Why can't one switch back to the default mode on Magento 2?
-
29-09-2020 - |
Question
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
Solution
The default mode is neither here nor there.
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.
OTHER TIPS
The default mode is there only to install Magento 2.
It should not be used for development or production.
After installation you can only switch between dev and prod.
Source: Alan Kent @MagentoImagine2016
As a windows developer, in developer mode, Magento wants to create symbolic links to the static assets, but uses the Linux command and not the windows command. This creates a lot of errors in the js and css files.
To switch back to default mode, open:-
app/etc/env.php
And change:-
'MAGE_MODE' => 'developer',
Back to:-
'MAGE_MODE' => 'default',
And re-deploy static files again.
I ran with the same problem, but changing it in env.php
manually works.