Introduction
If eCommerce sites using the Magento 2 platform are upgraded to certain versions, users may experience this error when loading site pages.
If this issue does appear, it occurs frequently and may prevent key JavaScript elements, like the Add to Cart and Login buttons, from functioning correctly.
Issue Description
Error Signature:
JS Error: Cannot read properties of undefined (reading remove)
Error Message:
Cannot read properties of undefined (reading 'remove')
Error Filename:
…/Magento_Customer/js/customer-data.min.js
Error Code Snippet:
remove: function(sections) { _.each(sections, function(sectionName) { storage.remove(sectionName); if (!sectionConfig.isClientSideSection(sectionName)) { storageInvalidation.set(sectionName, true); } }); }
Issue Background
This error originates from the storage.remove(sectionName)
function call made within the remove
function. Since storage
is undefined, the entire function fails.
This issue initially occurred when Magento upgraded from version 2.3.6 to version 2.4. During this update, Magento changed how it initializes storage. More specifically, storage initialization is now a wrapped function and no longer available at a global level.
A patch was developed and released to resolve the issue. The fix was merged into Magento version 2.4.3.
Unfortunately, during the update to version 2.4.5, this fix was removed for unknown reasons, and the error returned.
Potential Solution
Consult the resources below for context surrounding the issue's cause and solution:
Please proceed only if you feel comfortable making manual changes to your Magento instance. Magento will likely re-release the issue's fix in a future version.
As of Magento version 2.4.5 (October 2022), the fix is to manually apply a patch that reverses the previous fix's removal. The patch content can be found here.
Simply add this to a patch file and follow these steps to add this to your Magento instance.