I'm using Magento 2.2.6 version, I already set to developer mode, but when I ran setup:upgrade
, and when I open my Magento project the css and js not loaded.
But after I ran setup:static-content:deploy -f
,it backs to normal.
4 Answers
setup:upgrade cleans all the files in the directories
- /generated/code/
- /generated/metadata/
- /pub/static/
- and also deletes file deployed_version.txt
however force deploy - php bin/magento setup:static-content:deploy -f in developer mode regenerates all the above folders and files and recreates
- /pub/static/deployed_version.txt back again along with
- /var/view_preprocessed
hope this helps
The static view files deployment command enables you to write static files to the Magento file system when the Magento software is set for production mode.
The term static view file refers to the following:
- “Static” means it can be cached for a site (that is, the file is not dynamically generated). Examples include images and CSS generated from LESS.
- “View” refers to the presentation layer (from MVC).
Static view file deployment is affected by Magento modes as follows:
- Default and developer modes: Magento generates them on demand, but the rest are cached in a file for speed of access.
- Production mode: Static files are not generated or cached.
Solution
However, it only requires mode
to be set to the developer in your case.
bin/magento deploy:mode:set developer
How to view static content deploy errors in Magento 2?
Magento users when running php bin/magento setup:static-content:deploy have had some errors in their theme and they have to go through all the LESS file to check for errors manually. In fact, there are several types of errors that can be triggered by the deployment.
First you can see that Exception is handled directly in the execution
in Magento/Deploy/Console/Command/DeployStaticContentCommand.php:
catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>>');
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE)
{
$output->writeln($e->getTraceAsString());
}
return;
}
To regard the errors that are counted, you need to look into the Magento/Deploy/Model/Deployer
class, and the output you got is written by the deploy() method:
$this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");
Now if you check when this errorCount variable is incremented, we will find the in the deployFile() method as below:
catch (\Exception $exception) {
$this->output->write('.');
$this->verboseLog($exception->getTraceAsString());
$this->errorCount++;
}
And the verboseLog() method will just outputs when the command is run on verbose mode:
private function verboseLog($message)
{
if ($this->output->isVerbose()) {
$this->output->writeln($message);
}
}
And then you need to run following command to see the errors:
php bin/magento setup:static-content:deploy -v
If it doesn't work, you will try the extra verbose:
php bin/magento setup:static-content:deploy -vv
php bin/magento setup:static-content:deploy -vvv
I also had the same issue trying to deploy static content again and again after using upgrade command, however we do have the option of --keep-generated with setup:upgrade. It will keep static content. that's what I have learned so far. You can also combine two command incase you need not write them again and again:
Keep already generated static files:
php bin/magento setup:upgrade --keep-generated
Two commands in one go:
php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy
This usually solves my problem of writing one command instead of two.
setup:static-content:deploy -f
with language. like en_US en_GB