TypeError: Cannot read properties of undefined (reading ‘replace’)
-
Hi team,
I’m having an issue with the WooCommerce Home/Analysis dashboard (WooCommerce Admin). When I open WooCommerce → Home / Analysis, the page crashes and shows an error screen. In the browser console I consistently get:
TypeError: Cannot read properties of undefined (reading 'replace')and the stack trace points to WooCommerce Admin / WordPress core scripts, for example:
at ll (https://aoralife.com/wp-content/plugins/woocommerce/assets/client/admin/components/index.js?ver=aaab180e037e84550a39:2:600773) at https://aoralife.com/wp-includes/js/dist/viewport.min.js?ver=f07b4909c08cfe9de4e2:2:1394 at WithViewportMatch(ll) (https://aoralife.com/wp-includes/js/dist/compose.min.js?ver=7a9b375d8c19cf9d3d9b:9:13904) at v (https://aoralife.com/wp-content/plugins/woocommerce/assets/client/admin/chunks/dashboard-charts.js?ver=f5522d7a910eb9fa154d:1:775) at https://aoralife.com/wp-includes/js/dist/data.min.js?ver=f940198280891b0b6318:9:3361 ... at D (https://aoralife.com/wp-content/plugins/woocommerce/assets/client/admin/chunks/customizable-dashboard.js?ver=f76e89c4d8f4e59ce880:1:6906) ... at G (https://aoralife.com/wp-content/plugins/woocommerce/assets/client/admin/app/index.js?ver=0cd23dbb9aaf179ae6e6:2:523670)What I’ve tried so far (no fix):
- Switched site language to English and back.
- Disabled JS/CSS minify/combine/defer and fully disabled WP Fastest Cache.
- Purged all caches (plugin + CDN/hosting where possible).
- Ran WooCommerce Status → Tools (cleared analytics cache, transients, regenerated analytics tables, updated inbox notifications, etc.).
- Reinstalled WooCommerce.
- Removed any custom code/snippets I had added.
- Created a brand-new admin user and tested — same issue.
So the problem seems global to wc-admin (not user-specific) and likely a plugin conflict or a compatibility issue with the current WordPress/WooCommerce versions. Could you advise on next steps or confirm if this is a known issue?
Thanks!
The page I need help with: [log in to see the link]
-
Hi @gillavry,
I can see how frustrating this is, especially when the same error keeps appearing across multiple sites and interrupts access to the WooCommerce Analytics dashboard. I want to help make sure we approach this in the most effective way for your specific setup.
At this point, this is not identified as a known WooCommerce bug, as we have not been able to reproduce it consistently and it is not affecting all users. Based on what we are seeing, the behaviour is most likely related to something specific to the site environment, such as a browser related issue, the hosting setup, the PHP version in use, or a conflict with another plugin or custom code running alongside WooCommerce.
To help narrow this down, can you please confirm if you have already tried the temporary workaround shared earlier by @fonderco, and let us know whether it had any effect on your site. It would also be helpful to know if you have tested this using a different browser or an incognito or private window, to rule out any browser level conflicts.
Because each site has its own configuration, we are unable to troubleshoot individual setups within a shared thread like this. The best next step is to open your own support topic so we can look into your environment in detail and provide guidance that is specific to your site.
You can open a new topic here https://ww.wp.xz.cn/support/plugin/woocommerce/#new-post
Once you do, please include when you first noticed the issue, your WordPress and WooCommerce versions, the full console error, and your WooCommerce system status report shared via https://pastebin.com or https://quickforget.com. That will allow us to dig in properly and move this forward with you.
Looking forward to your update so we can continue from there.
/!\ This analysis and fix were generated with Claude Code
WooCommerce 9.9.x + WordPress 6.9 – TypeError: Cannot read properties of undefined (reading ‘replace’) – Root cause and fix
Root cause
The crash happens in the Chart component (components/index.js). The render method destructures itemsLabel from this.props and passes it to sprintf:
const { ..., itemsLabel: b, ... } = this.props;
// ...
totalLabel: (0, y.sprintf)(b, T.length)
When the Chart is rendered from the Dashboard Charts section (dashboard-charts.js), the parent component (ReportChart) never receives itemsLabel as a prop — it simply isn’t passed.So b is undefined, and sprintf(undefined, …) crashes on string.replace(…) inside @wordpress/i18n.
This only affects the Dashboard overview. The Analytics report pages (Products, Revenue, etc.) correctly pass itemsLabel, which is why they work fine.
Why patching wp.i18n.sprintf is not straightforward
WordPress’s @wordpress/i18n module uses webpack harmony exports. The sprintf property on wp.i18n is defined via:Object.defineProperty(exports, "sprintf", { enumerable: true, get: () => sprintf_sprintf });This creates a non-configurable getter with no setter. That means:
– wp.i18n.sprintf = myPatchedFn → silently ignored
– Object.defineProperty(wp.i18n, “sprintf”, { value: myFn }) → throws TypeError (non-configurable)
The fix
The solution is to replace the entire window.wp.i18n object with a new one right after wp-i18n loads, but before WooCommerce scripts capture the reference via window[“wp”][“i18n”].
Create a must-use plugin (wp-content/mu-plugins/wc-sprintf-fix.php):
<?php
/**
* Plugin Name: WooCommerce sprintf Fix
* Description: Fixes WooCommerce 9.9.x sprintf crash (undefined itemsLabel in dashboard charts).
* Version: 1.0.0
*
* @see https://ww.wp.xz.cn/support/topic/typeerror-cannot-read-properties-of-undefined-reading-replace-2/
*/
if (!defined('ABSPATH')) {
exit;
}
add_filter('script_loader_tag', function ($tag, $handle) {
if ($handle !== 'wp-i18n') {
return $tag;
}
$patch = <<<'JS'
<script>
(function() {
var orig = window.wp.i18n;
if (!orig || !orig.sprintf) return;
var origSprintf = orig.sprintf;
var newI18n = {};
var keys = Object.getOwnPropertyNames(orig);
for (var i = 0; i < keys.length; i++) {
if (keys[i] === "sprintf") {
newI18n.sprintf = function() {
var a = [].slice.call(arguments);
if (a[0] == null) a[0] = "";
return origSprintf.apply(this, a);
};
} else {
Object.defineProperty(newI18n, keys[i], Object.getOwnPropertyDescriptor(orig, keys[i]));
}
}
window.wp.i18n = newI18n;
})();
</script>
JS;
return $tag . $patch;
}, 10, 2);
Expected fix from WooCommerce
The proper fix would be for WooCommerce to either:
1. Add itemsLabel to Chart.defaultProps (e.g. itemsLabel: __(‘%d items’, ‘woocommerce’))
2. Or pass itemsLabel from the dashboard charts component to ReportChart
Both fixes are one-liners. Until then, the mu-plugin above works as a safe workaround that can be removed once WooCommerce ships the fix.
Hope this helps others running into this issue!Note: It’s also possible that this issue is triggered by specific data conditions. In my case (and potentially for other users experiencing this), certain product or order data
configurations in the dashboard charts might cause the itemsLabel prop to not be resolved correctly. If you’re seeing this error intermittently or only with certain date ranges, your data
might be a contributing factor — but the underlying bug remains that sprintf should handle undefined gracefully rather than crashing./!\ This analysis and fix were generated with Claude Code
Hi there!
Thank you for providing such a detailed analysis and explanation of the issue. We appreciate the time you took to document the root cause and the workaround.I’ll make sure to pass this information along to our development team for further review. Your insights will be helpful in investigating and addressing this behavior in future updates.
Before you go, If you’re happy with the support you received, would you consider leaving us a quick review? It really helps us out:https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/#new-post
Thank you
You must be logged in to reply to this topic.