Closed jakeorr closed 1 month ago
I was able to resolve the issue by using the utils from libphonenumber-js directly:
import { type CountryCode, default as parsePhoneNumber, getCountryCallingCode } from 'libphonenumber-js';
For the format functions I used the parsed number's functions:
const parsed = parsePhoneNumber(phone);
return parsed.formatInternational();
// or return parsed.formatNational();
Sort of a workaround, but likely how the packages are expected to be used. This will work for me.
Hello! Thanks for the useful phone number package. We've been able to successfully rely on it for our client-side needs.
I've run into issues when I try to use parts of the package on the react server-side though. In my use case we are rendering React code on the server to convert to a PDF. The important part is that there is no client side rendering taking place, so solutions with "use client" aren't an option.
When I run the following function on the server, it generates an error
Here's the error:
It looks like
react-phone-number-input
uses a single barrel file which includes all the imports, and it is a known issue that tree-shaking doesn't work with typescript barrel files. I suspect that is why I'm seeing this issue. I think what would solve this would be to also provide utility exports separately in another spot that didn't also pull in react code. Something likeimport { ...utils... } from 'react-phone-number-input/core'
.Env
Next.js 13 React 18