Cannot read properties of undefined (reading 'data')
This error is usually nothing to worry about. It tends to happen when losing internet connectivity or being automatically logged out.
Edited: 2023-10-16 09:24
Cannot read properties of undefined (reading 'data')
This is a really old and nasty error notification in Shopware, and it usually happens when losing internet connectivity. It is nothing to worry about, but the notification is annoying; such errors are best placed in a log file, or perhaps in the browser console – it's not relevant to users.
It happens because Shopware is constantly sending XHR requests in the background, and when these HTTP requests are then unable to reach the server, it will result in Cannot read properties of undefined errors.
I hope Shopware is going to eventually fix it, but until then, you can apply a temporary fix so the notification will not bother your users.
I have also seen various variations of this error; I still suspect the error is caused by being automatically logged out. Here is another variation of the error:
Cannot read properties of undefined (reading 'config')
And another one:
Cannot read properties of undefined (reading 'trim')
A temporary fix
E.g. In line 33 of the admin-notification-worker.js file:
/var/www/vendor/shopware/administration/Resources/app/administration/src/core/worker/admin-notification-worker.js
You can simply add a check for "Cannot read properties of undefined":
if (false == error.message.includes("Cannot read properties of undefined")) {this.createNotification('error', error.message);}
This fix should only be temporary, and it will automatically be overwritten when Shopware is updated, and by then, hopefully, Shopware will have removed such "meaningless" notifications from the users sight :-)
And specifically it is the loadNotifications method in the file you need to modify.
Be careful when editing system files!
System files should, of course, rarely, if ever, be edited directly. When you decide to do so, you should keep in mind that your changes will be overwritten when updating the system. Sometimes you want this to happen, but other times you don't.
It's usually best if you can add modifications you want to keep either in your shop's theme or in a custom plugin.
Tell us what you think:
Thanks a lot! But one question - how to compile administration-js on production? When I make changes on production in this file - this error message appears again.
For developer-version it works after ./psh.phar administration:build but production-version doesn't have psh.phar.
Yurii, you run the build scripts in the bin/ folder. E.g. sudo -u www-data bin/build-storefront.sh
This should build not only the JavaScript for the storefront, but also the .SCSS. Hope it helps.