magento2: Executing `grunt refresh` or `grunt exec:all` in production mode, leads to error "Unable to retrieve deployment version of static files from the file system."
Preconditions (*)
- Magento 2.3.5-p2
Steps to reproduce (*)
- Make the folder
pubyour project root - Put magento in production mode.
php bin/magento deploy:mode:set production - Create a theme.
- Setup grunt.
- Execute
grunt exec:all
Expected result (*)
- It should compile.
Actual result (*)
- You will get Unable to retrieve deployment version of static files from the file system. and the command fails and the file
pub/static/deployed_version.txtgets deleted.
This error is getting logged:
[2020-08-17 05:25:31] report.CRITICAL: Can not load static content version. [] []
[2020-08-17 05:25:31] report.ERROR: Unable to retrieve deployment version of static files from the file system.
#0 vendor/magento/framework/App/View/Deployment/Version.php(67): Magento\Framework\App\View\Deployment\Version->readValue('production')
#1 vendor/magento/module-theme/Model/Url/Plugin/Signature.php(87): Magento\Framework\App\View\Deployment\Version->getValue()
#2 vendor/magento/module-theme/Model/Url/Plugin/Signature.php(65): Magento\Theme\Model\Url\Plugin\Signature->renderUrlSignature()
#3 vendor/magento/framework/Interception/Interceptor.php(146): Magento\Theme\Model\Url\Plugin\Signature->afterGetBaseUrl(Object(Magento\Store\Model\Store\Interceptor), 'https://relaunc...', 'static', $
#4 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Store\Model\Store\Interceptor->Magento\Framework\Interception\{closure}('static', false)
#5 generated/code/Magento/Store/Model/Store/Interceptor.php(143): Magento\Store\Model\Store\Interceptor->___callPlugins('getBaseUrl', Array, Array)
#6 vendor/magento/framework/Url.php(482): Magento\Store\Model\Store\Interceptor->getBaseUrl('static', false)
#7 vendor/magento/framework/View/Asset/Repository.php(284): Magento\Framework\Url->getBaseUrl(Array)
#8 vendor/magento/framework/View/Asset/Repository.php(233): Magento\Framework\View\Asset\Repository->getFallbackContext('static', NULL, 'frontend', 'company/fresh', 'de_DE')
#9 vendor/magento/module-developer/Console/Command/SourceThemeDeployCommand.php(172): Magento\Framework\View\Asset\Repository->createAsset('css/styles-m.le...', Array)
#10 vendor/symfony/console/Command/Command.php(255): Magento\Developer\Console\Command\SourceThemeDeployCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Con$
#11 vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output$
#12 vendor/magento/framework/Interception/Interceptor.php(138): Magento\Developer\Console\Command\SourceThemeDeployCommand\Interceptor->___callParent('run', Array)
#13 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Developer\Console\Command\SourceThemeDeployCommand\Interceptor->Magento\Framework\Interception\{closure}(Object(Symfony\Componen$
#14 generated/code/Magento/Developer/Console/Command/SourceThemeDeployCommand/Interceptor.php(104): Magento\Developer\Console\Command\SourceThemeDeployCommand\Interceptor->___callPlugins('run', Array,$
#15 vendor/symfony/console/Application.php(1000): Magento\Developer\Console\Command\SourceThemeDeployCommand\Interceptor->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Componen$
#16 vendor/symfony/console/Application.php(271): Symfony\Component\Console\Application->doRunCommand(Object(Magento\Developer\Console\Command\SourceThemeDeployCommand\Interceptor), Object(Symfony\Comp$
#17 vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput$
#18 vendor/symfony/console/Application.php(147): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 bin/magento(23): Symfony\Component\Console\Application->run()
#20 {main} [] []
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (7 by maintainers)
@Eddcapone
setup:di:compilehas nothing to do with generating static assetssetup:upgradealso implicitly executessetup:static-content:deploy(unless you specify the--keep-generatedflag)setup:static-content:deployon production is because it does a lot more than simply compiling less code. It’s also merging/bundling/minifying css and javascript and html if you have those settings enabled. It’s also responsible for generating javascript translations and might do some more tasks. I don’t know if grunt can also do all these tasks by default in Magento? I’ve discussed this before in another ticket.If you want steps for a production deploy, here are the basic ones which we perform:
These are just basic steps, we do a lot of complex other things due to how our workflow is setup, but hopefully this can put you in the correct direction 🙂
I see thank you. I just tried
php bin/magento maintenance:enable && grunt clean && php bin/magento setup:static-content:deploy && php bin/magento setup:static-content:deploy de_DE && php bin/magento maintenance:disableinstead.That worked.
That’s because you start from dirty directories, Magento uses previously generated files in their SCD procedures and doesn’t always overwrite them. If you start from a clean environment (like we always do with every single new deploy to production) it should work.
In your case, please try removing these files before running
setup:static-content:deploy:rm -R var/view_preprocessed/*rm -R pub/static/*(the
*is important and intentionally, so you won’t accidentally remove the.htaccessfiles in those directories which is important to keep if you use Apache as your webserver)Php compiler gives a bit different result time to time, that’s the main reason - you might see the issues that no one else see
On Tue, 18 Aug 2020 at 13:09 Eddcapone notifications@github.com wrote:
@Eddcapone: you can use https://github.com/baldwin-agency/magento2-module-less-js-compiler which uses nodejs to compile less code instead of php, which - in the early days of Magento was much more performant, but recently the scales have tipped. But the most important feature of that module, is that the outputted css code should be 100% the same between local development (using grunt) and production (using
setup:static-content:deploy) which is not the case if you use the build-in php less compiler which Magento ships with.From: https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/tools/using_grunt.html
Prerequisites
Make sure that you set your Magento application to the developer or default mode.
I figured out that
grunt execcalls this code:grunt --force clean:company_fresh. This calls the script dev/tools/grunt/configs/clean.js.It looks like this script is deleting the file pub/static/deployed_content.txt and so the errors Unable to retrieve deployment version of static files from the file system and Can not load static content version. are showing.
So I modified the script and removed all lines where “deployedVersion” is showing.
Original:
Fix:
Now if I call
grunt refresh && php bin/magento setup:static-content:deploy && php bin/magento setup:static-content:deploy de_DEthen it works. So why is the clean script deleting the file by default and causing the bug? It only happens in production mode.