react-phone-input-2 icon indicating copy to clipboard operation
react-phone-input-2 copied to clipboard

Minified React error #130

Open FacuCarbon opened this issue 2 years ago • 18 comments

Hello! first to congratulate for the operation, it is exquisite. On the other hand, locally it works perfectly for me. But when uploading it to production, I get the error: Uncaught Error: Minified React error #130 with the component, I use vite, do you have any solution? Thank you so much.

FacuCarbon avatar May 02 '22 13:05 FacuCarbon

Have the same minification issue. It's something with imports.

This package needs to update!

To recreate just use Vite build and this will try to minify and break

nerijusgood avatar May 10 '22 13:05 nerijusgood

This needs a real fix for sure, but as a workaround I was able to get it to work by doing this:

import PI from "react-phone-input-2";
const ReactPhoneInput = PI.default ? PI.default : PI;

rogorman9 avatar May 12 '22 16:05 rogorman9

@rogorman9 Thank you very much! this solution worked for me. Could you explain a little more why it happens?

FacuCarbon avatar May 17 '22 16:05 FacuCarbon

I'm using react-phone-input-2 too with vite and React Ts and stuck on the same issue. @rogorman9 workaround didn't work for me. The type checker says "Property 'default' does not exist on type 'FC<PhoneInputProps>' ". They should take a look at this issue

femi-Zedev avatar Jul 24 '22 17:07 femi-Zedev

ReactPhoneInput

Finaly I managed to make it work. I convert my component to JSX to avoid type checking

femi-Zedev avatar Jul 24 '22 18:07 femi-Zedev

Dirty fix for TSX

const ReactPhoneInput = (PI as any).default !== null ? (PI as any).default : PI

Thibaud05 avatar Sep 27 '22 13:09 Thibaud05

So I come with a workound that works for both dev and prod. It's just litteraly checking environment mode. To do so you have to import React Phone Input like in previous workaround by @Thibaud05 and based on env mode apply the fix import PI from "react-phone-input-2"; const ReactPhoneInput = import.meta.env.PROD ? (PI as any).default : PI; Note that I use import.meta.env.PROD because of Vite. If you are using CRA consider using process.env.NODE_ENV === 'development' to check if your are in prod or dev

femi-Zedev avatar Nov 14 '22 16:11 femi-Zedev

@arnaudakotonou97 great

TawalMc avatar Nov 14 '22 16:11 TawalMc

This needs a real fix for sure, but as a workaround I was able to get it to work by doing this:

import PI from "react-phone-input-2";
const ReactPhoneInput = PI.default ? PI.default : PI;

Thank you very much! I am using React 18 , this works!

Sashankr avatar Jan 04 '23 20:01 Sashankr

I published a package based on #532 changes because PR is still pending and my codebase need it urgently. You can just find and replace all the occurrences of react-phone-input-2 to vreact-phone-input. vreact-phone-input

zeyarpaing avatar Jan 09 '23 15:01 zeyarpaing

Dirty fix for TSX

const ReactPhoneInput = (PI as any).default !== null ? (PI as any).default : PI

It works for me! Thanks a lot!

ValterNeto9 avatar Jan 13 '23 02:01 ValterNeto9

Hello! first to congratulate for the operation, it is exquisite. On the other hand, locally it works perfectly for me. But when uploading it to production, I get the error: Uncaught Error: Minified React error #130 with the component, I use vite, do you have any solution? Thank you so much.

I faced the same problem! your thread save my life. Thanks man!

ValterNeto9 avatar Jan 13 '23 02:01 ValterNeto9

thanks it work

JulesImbert avatar Feb 17 '23 12:02 JulesImbert

@rogorman9 ; Thanks man! this solution worked

ahsan-khan1999 avatar Mar 15 '23 14:03 ahsan-khan1999

Hello, same issue here I will go with the workaround 👍 If you want to keep typesafety this solution works:

import React from 'react'
import PI, { PhoneInputProps } from 'react-phone-input-2'

const ReactPhoneInput: React.FC<PhoneInputProps> = (PI as any).default || PI

@bl00mber @rebebop do you plan a long term fix for this ?

gamegee avatar Apr 14 '23 09:04 gamegee

@gamegee I haven't updated that package in a long time. But I'll take a look at it over the weekend to see if I can add a quick fix to it.

sample-usr avatar Apr 14 '23 09:04 sample-usr

const ReactPhoneInput = (RPI as any).default ? (RPI as any).default : RPI;

If I am using this, I am not able to use countryCodeEditable={false} and country code is deleteable, and if I don't use the above code, my code is breaking in production server.

chaudharyShub avatar May 03 '23 13:05 chaudharyShub

const ReactPhoneInput = (RPI as any).default ? (RPI as any).default : RPI;

Si estoy usando esto, no puedo usar countryCodeEditable={false} y el código de país se puede eliminar, y si no uso el código anterior, mi código se está rompiendo en el servidor de producción.

Me pasó lo mismo y lo solucioné creando un componente ts de esta manera:

import PI from "react-phone-input-2"; const ReactPhoneInput = import.meta.env.PROD ? (PI as any).default : PI; export default ReactPhoneInput;

y en la vista necesaria directamente lo importas y lo podes usar normalmente. Aclaro que lo metí en un componente ts, para poder reutilizarlo a lo largo de mi aplicación.

import ReactPhoneInput from "../phone/Phone";

FacuCarbon avatar May 03 '23 14:05 FacuCarbon