-
Bug reportDescribe the bugI am trying to format number to locale string by setting explicit locale. Usage: To ReproduceUse following component: eur-to-hrk.tsx interface EurToHrkProps {
price: number;
}
const EurToHrk = ({ price }: EurToHrkProps) => {
return (
<>
{new Intl.NumberFormat("hr-HR", { style: "currency", currency: "EUR" }).format(price)}
~
{new Intl.NumberFormat("hr-HR", { style: "currency", currency: "HRK" }).format(price * 7.52)}
</>
);
};
export default EurToHrk; index.tsx const Home = () => {
return (
<>
<Head>
<title>Home</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<EurToHrk price={5000} />
</>
);
}; Expected behaviorServer and client side to be aligned as explicit locale was passed. System information
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
We had a similar error in a financial related product we currently develop. The problem is not with nextJS in this case, but with node itself. The Intl number format is managed through nodes internationalization modules. And - long story short - node runs by default only with the en-US settings when its comes to date/time formatting, money formatting and the likes. You need to explicitly enable additional locales, or node will just default to the standard formatter. There is an npm package which adds support for all ICU modules. After installing it, you need to tell the node process to use the ICU definitions from that package. You can do that by adding an ENV variable to the start/dev/build scripts in the "scripts": {
"test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"dev": "cross-env NODE_ICU_DATA=node_modules/full-icu next",
"build": "cross-env NODE_ICU_DATA=node_modules/full-icu next build",
"start": "cross-env NODE_ICU_DATA=node_modules/full-icu next start",
}, We also applied Hope this fixes your problem! |
Beta Was this translation helpful? Give feedback.
-
the problem should be solved in node v14.x.x |
Beta Was this translation helpful? Give feedback.
-
Hit this problem with locale Followed thread of issues, first in the node github, this is a problem in V8 |
Beta Was this translation helpful? Give feedback.
-
I've also faced this issue with locale I'm using node 18.17.0 |
Beta Was this translation helpful? Give feedback.
-
issue with locale uk-UA and currency UAH too |
Beta Was this translation helpful? Give feedback.
-
+1 with locale uk-UA and currency UAH |
Beta Was this translation helpful? Give feedback.
-
As a temporary solution, you can use suppressHydrationWarning and looks like we should wait for fixes in future versions of node |
Beta Was this translation helpful? Give feedback.
the problem should be solved in node v14.x.x