Magento 2 - Can't compile theme in production mode anymore | Unable to retrieve deployment version of static files from the file system

magento.stackexchange https://magento.stackexchange.com/questions/319989

Question

I get this error when trying to execute grunt refresh or grunt exec:all.

[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} [] []

My store is set to production mode my root directory is set to /pub. The problem appeared suddenly, before it always worked.

How can I solve it, without setting my store to development mode?

I noticed that the file pub/static/deployed_version.txt was missing, so I executed php bin/magento setup:static-content:deploy -f, then the file was created. Then I executed grunt exec:all again. But then the error shows and the file gets deleted again.

Was it helpful?

Solution

I figured out that grunt exec calls 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:

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

'use strict';

var themes = require('../tools/files-router').get('themes'),
    _      = require('underscore');

var themeOptions = {};

_.each(themes, function(theme, name) {
    themeOptions[name] = {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= combo.autopath(\""+name+"\", path.pub ) %>**/*",
                    "<%= combo.autopath(\""+name+"\", path.tmpLess) %>**/*",
                    "<%= combo.autopath(\""+name+"\", path.tmpSource) %>**/*",
                    "<%= path.deployedVersion %>"
                ]
            }
        ]
    };
});

var cleanOptions = {
    "var": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.tmp %>/generation/**/*",
                    "<%= path.tmp %>/log/**/*",
                    "<%= path.tmp %>/maps/**/*",
                    "<%= path.tmp %>/page_cache/**/*",
                    "<%= path.tmp %>/tmp/**/*",
                    "<%= path.tmp %>/view/**/*",
                    "<%= path.tmp %>/view_preprocessed/**/*"
                ]
            }
        ]
    },
    "pub": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                "dot": true,
                "src": [
                    "<%= path.pub %>frontend/**/*",
                    "<%= path.pub %>adminhtml/**/*",
                    "<%= path.deployedVersion %>"
                ]
            }
        ]
    },
    "styles": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/view_preprocessed/**/*",
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.pub %>frontend/**/*.less",
                    "<%= path.pub %>frontend/**/*.css",
                    "<%= path.pub %>adminhtml/**/*.less",
                    "<%= path.pub %>adminhtml/**/*.css",
                    "<%= path.deployedVersion %>"
                ]
            }
        ]
    },
    "markup": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.tmp %>/generation/**/*",
                    "<%= path.tmp %>/view_preprocessed/html/**/*",
                    "<%= path.tmp %>/page_cache/**/*"
                ]
            }
        ]
    },
    "js": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.pub %>**/*.js",
                    "<%= path.pub %>**/*.html",
                    "<%= path.pub %>_requirejs/**/*",
                    "<%= path.deployedVersion %>"
                ]
            }
        ]
    }
};

module.exports = _.extend(cleanOptions, themeOptions);

Fix:

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

'use strict';

var themes = require('../tools/files-router').get('themes'),
    _      = require('underscore');

var themeOptions = {};

_.each(themes, function(theme, name) {
    themeOptions[name] = {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= combo.autopath(\""+name+"\", path.pub ) %>**/*",
                    "<%= combo.autopath(\""+name+"\", path.tmpLess) %>**/*",
                    "<%= combo.autopath(\""+name+"\", path.tmpSource) %>**/*",
                ]
            }
        ]
    };
});

var cleanOptions = {
    "var": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.tmp %>/generation/**/*",
                    "<%= path.tmp %>/log/**/*",
                    "<%= path.tmp %>/maps/**/*",
                    "<%= path.tmp %>/page_cache/**/*",
                    "<%= path.tmp %>/tmp/**/*",
                    "<%= path.tmp %>/view/**/*",
                    "<%= path.tmp %>/view_preprocessed/**/*"
                ]
            }
        ]
    },
    "pub": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                "dot": true,
                "src": [
                    "<%= path.pub %>frontend/**/*",
                    "<%= path.pub %>adminhtml/**/*",
                ]
            }
        ]
    },
    "styles": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/view_preprocessed/**/*",
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.pub %>frontend/**/*.less",
                    "<%= path.pub %>frontend/**/*.css",
                    "<%= path.pub %>adminhtml/**/*.less",
                    "<%= path.pub %>adminhtml/**/*.css",
                ]
            }
        ]
    },
    "markup": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.tmp %>/cache/**/*",
                    "<%= path.tmp %>/generation/**/*",
                    "<%= path.tmp %>/view_preprocessed/html/**/*",
                    "<%= path.tmp %>/page_cache/**/*"
                ]
            }
        ]
    },
    "js": {
        "force": true,
        "files": [
            {
                "force": true,
                "dot": true,
                "src": [
                    "<%= path.pub %>**/*.js",
                    "<%= path.pub %>**/*.html",
                    "<%= path.pub %>_requirejs/**/*",
                ]
            }
        ]
    }
};

module.exports = _.extend(cleanOptions, themeOptions);

Now if I call grunt refresh && php bin/magento setup:static-content:deploy && php bin/magento setup:static-content:deploy de_DE then it works.

I created a bug report: https://github.com/magento/magento2/issues/29570

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top