Next.js Discord

Discord Forum

Uploading NextJS to Vercel

Answered
Sjödda posted this in #help-forum
Open in Discord
Hey,

I uploading my NextJS project to Vercel, but I keep getting the error: navigator is not defined.
However, I can run npm run build perfectly fine on my own computer.
Only when I upload the project, and Vercel runs npm run build, it gives me that error.
I don't mention navigator anywhere in the codebase, I don't think.

Here's the github repo:
https://github.com/ilittlebig/eliasmattor-development

Thank you!
Answered by Ray
const currencyFormatter = (
  amount: number,
  currency: string,
  locale: string = navigator.language
): string => {
  if (typeof window === "undefined") return "";
  return new Intl.NumberFormat(locale, {
    style: "currency",
    currency: currency,
  }).format(amount);
};

export default currencyFormatter;
View full answer

6 Replies