Minified assets not found or generated during build phase
In Adobe Commerce Cloud, minified assets return a 404 error after deployment due to file system issues or improper configuration of .magento.env.yaml or config.php files. To fix this, check file permissions to ensure they’re accessible by the web server, and verify that the.magento.env.yaml and app/etc/config.php files are configured correctly for your environment.
Description description
Environment
Adobe Commerce Cloud
Issue/Symptoms
After completing a website deployment, certain minified assets are inaccessible, for example, https://yourdomain.com/static/frontend/Namespace/theme/default/en_US/requirejs/require.min.js returns 404. It happens due to:
-
File system issues that prevent the file from syncing across all web nodes.
-
Improper configuration of the
.magento.env.yamlorconfig.phpfile.- SCD on Build requires that asset minification settings be saved to
app/etc/config.phpin order to take effect. - The SCD settings (see environment variables) are not configured or added under the correct stage in the
.magento.env.yamlfile.
- SCD on Build requires that asset minification settings be saved to
Resolution resolution
To resolve the issue:
-
First, check file permissions for the affected assets to ensure they are accessible by the web server.
- SSH to each web node and verify if the asset exists on all web nodes. (Note: On a non-split architecture, there will only be three nodes. On a split architecture, the first three nodes will be service nodes, but there could potentially be more.) For node X:
magento-cloud ssh -p <cluster_id> -I X - Once you are on node X, run this command and check the permissions:
ls -la pub/static/frontend/Namespace/theme/default/en_US/requirejs/require.min.js(Note: Replace the filename in the command with the actual asset name that is returning a 404 error). - If the file exists on some nodes but not others, submit a support request with the Contact Reason set to Infrastructure Incident.
- SSH to each web node and verify if the asset exists on all web nodes. (Note: On a non-split architecture, there will only be three nodes. On a split architecture, the first three nodes will be service nodes, but there could potentially be more.) For node X:
-
Next, if the file doesn’t exist on all nodes, confirm that the
.magento.env.yamlandapp/etc/config.phpfiles are configured correctly for your environment.-
On any of the web nodes, first run this command:
vendor/bin/ece-tools wizard:scd-on-build -
If the above command returns SCD on build is enabled, run this command to verify that the asset minification settings are enabled:
grep -r minify_files app/etc/*.php. (Note: Replace the filename in the command with the actual asset name that is returning a 404 error). If the command returns no rows, it implies that minification is disabled. A value of0indicates that the item is disabled, and1means it is enabled. -
If there are no rows returned:
- Run the
config:dumpcommand to save the minification config toapp/etc/config.php(see Setting the SCD on build). - Commit it to the repository.
- Redeploy the instance.
- Run the
-
If any of the asset minification settings has a value of
0that should be minified:- Update the value in
app/etc/config.phpto1. - Commit it to the repository.
- Redeploy the instance.
- Update the value in
-
Check the
.magento.env.yamlfile and ensure that you have added the SCD Environment variableunder the proper stage:- SCD on Build: The Build variable should be placed under the
build:stage. - SCD on Deploy: The Deploy variable should be placed under the
deploy:stage. - After ensuring that the variable has been added under the appropriate stage, commit the file to the repository and redeploy the instance.
- SCD on Build: The Build variable should be placed under the
-
-
Finally, test access to the affected URLs after making adjustments.
If issues persist after performing these steps, please reach out to Adobe Support as further investigation into server logs or additional configuration settings may be required.