magento2
magento2 copied to clipboard
Error deploying static content when dev/js/minify_files is enabled in db but disabled at config.php
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.
- [X] 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”.
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:
-
@magento give me 2.4-develop instance
- upcoming 2.4.x release - For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this
- To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: 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.
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: :point_down:
- [ ] 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
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced 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.
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.
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.
Hello @JamesFX2,
We would need more information on that, can you please elaborate on the same.
Hello @JamesFX2,
Could you please let us know the use case and when are you getting this issue.
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.