Skip to content

Commit

Permalink
fix: prevent <PrismicNextImage> "Element type is invalid" error (#79)
Browse files Browse the repository at this point in the history
* fix: prevent `<PrismicNextImage>` "Element type is invalid" error

* fix: compat with TypeScript < 4.9

* fix: actual fix for TypeScript < 4.9
  • Loading branch information
angeloashmore authored Jul 5, 2023
1 parent 186d1b3 commit f002052
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/PrismicNextImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,16 @@ export const PrismicNextImage = ({
);
}

// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.
// `next/image` seems to be affected by a default + named export bundling bug.
let ResolvedImage = Image;
if ("default" in ResolvedImage) {
ResolvedImage = (ResolvedImage as unknown as { default: typeof Image })
.default;
}

return (
<Image
<ResolvedImage
src={src}
width={fill ? undefined : resolvedWidth}
height={fill ? undefined : resolvedHeight}
Expand Down

0 comments on commit f002052

Please sign in to comment.