I'm setting a component as dynamically callable:
index.tsx
import dynamic from "next/dynamic";
import { PhoneNumberInputProps } from "./components/PhoneNumberInput";
const PhoneNumberInput = dynamic<PhoneNumberInputProps>(
() => import("./components/PhoneNumberInput") as any
);
components/PhoneNumberInput.tsx
...
import PhoneInput from "react-phone-number-input";
...
export type PhoneNumberInputProps = {...};
export const PhoneNumberInput = ({...}: PhoneNumberInputProps) => {
...
}
So, react-phone-number-input shouldn't be part of the initial bundle, right? but when I analyze it it is still present. Why?
In order to remove the file
PhoneNumberInput.tsxfrom the bundle you need to remove the import inindex.tsto./components/PhoneNumberInput.For
PhoneNumberInputPropsyou can move that type to its own file, or just change the type toAnyto test (if typescript is giving you a hard time).