Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error deploying static content when dev/js/minify_files is enabled in db but disabled at config.php #38117

Closed
1 of 5 tasks
JamesFX2 opened this issue Oct 24, 2023 · 7 comments
Closed
1 of 5 tasks
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.6-p3 Indicates original Magento version for the Issue report.

Comments

@JamesFX2
Copy link

Preconditions and environment

  • Magento version 2.4.6-p3
  • config:set dev/js/minify_files 1
  • php bin/magento setup:static-content:deploy en_US en_GB
  • Used Error happened during deploy process: The contents from the "/home/cloudpanel/htdocs/test.example.com/releases/2023_10_23_9_19_30_branch_production/pub/static/adminhtml/Magento/backend/en_US/requirejs-config.min.js" file can't be read. Warning!file_get_contents(/home/cloudpanel/htdocs/test.example.com/releases/2023_10_23_9_19_30_branch_production/pub/static/adminhtml/Magento/backend/en_US/requirejs-config.min.js): Failed to open stream: No such file or directory

Basically, in an edge case, neither requirejs-config.min.js nor requirejs-min-resolver.min.js are generated.

Steps to reproduce

This is caused by our config.php settings but the actual bug is the inconsistent behaviour this causes.

    system' => [
        'stores' => [
            'chem' => [
                'dev' => [
                    'template' => [
                        'minify_html' => '0'
                    ],
                    'js' => [
                        'minify_files' => '0',
                        'merge_files' => '0'
                    ],
                    'css' => [
                        'minify_files' => '0',
                        'merge_css_files' => '0'
                    ]
                ]
            ]
        ]
    ]

Whereas the core_config_data setting is 'dev/js/minify_files' 1 at default scope.

Expected result

Deployment successful.

Actual result

Error occurs preventing deployment

Additional information

During a setup:static-content:deploy, the requirejs-config.js and requirejs-min-resolver.js files are generated here

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Deploy/Service/DeployRequireJsConfig.php#L113-L115

At this stage, Magento tries to determine whether or not the files should be minified or not.

The function to determine whether not a filename should be minified or not is in \Magento\Framework\View\Asset\Minification, the function is called addMinifiedSign. During the process that GENERATES the files, the argument that is passed is just the file names, requirejs-min-resolver.js and requirejs-config.js - not the relative path.

See (1) https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/RequireJs/Config.php#L180C21-L183 and (2) https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/RequireJs/Config.php#L238-L244

So eventually requirejs-config.js is passed to the isEnabledForArea function and since the filename is passed, not the relative path, $area is !== 'adminhtml' and when $this->isEnabled('js') is called, it returns false, relevant code below.

https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Asset/Minification.php#L194-L215

When the generated files are later read, the relative path of "adminhtml/Magento/backend/en_US/requirejs-config.js" is later passed into the addMinifiedSign to try to determine the location of the file - because the path is now relative and has adminhtml as the area, it presumes that the path should be minified. This is the secondary source of the deployment error.

My recommendation is to modify \Magento\Framework\RequireJs\Config at points #1 and #2 so that getMinResolverRelativePath and getConfigFileRelativePath pass the relative path into addMinifiedSign to ensure consistency of behaviour.

Release note

No response

Triage and priority

  • 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”.
@m2-assistant
Copy link

m2-assistant bot commented Oct 24, 2023

Hi @JamesFX2. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@engcom-Bravo engcom-Bravo added the Reported on 2.4.6-p3 Indicates original Magento version for the Issue report. label Oct 25, 2023
@engcom-November engcom-November self-assigned this Jan 8, 2024
Copy link

m2-assistant bot commented Jan 8, 2024

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

Hello @JamesFX2,

Thank you for the report and collaboration!

Can you let us know the use case where you want the dev/js/minify_files enabled in db but disabled at config.php.

Thank you.

@engcom-November engcom-November added the Issue: needs update Additional information is require, waiting for response label Jan 8, 2024
@JamesFX2
Copy link
Author

JamesFX2 commented Jan 8, 2024

I would have to refresh my memory but I believe the issue is caused by scopes more than the specifics of the config.php and the way that scope is determined using a relative rather than absolute path. In retrospect, the only issue may be how scope is determined for the require files.

@engcom-November
Copy link
Contributor

Hello @JamesFX2,

We would need more information on that, can you please elaborate on the same.

@engcom-November
Copy link
Contributor

Hello @JamesFX2,

Could you please let us know the use case and when are you getting this issue.

@engcom-November
Copy link
Contributor

Hello @JamesFX2,

As there is no activity on this issue for a long time, we believe the issue has been resolved, hence closing this issue.
Feel free to raise a new issue or reopen this if you need more assistance.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.6-p3 Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests

3 participants