I am trying to register a custom component.
So far I was able to make it show up in plasmic studio, but once I publish it my code (project created via CLI / codegen), I see this error:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.
Check the render method of
PlasmicHomepage
.
I guess the issue is that I need to register it on every page where I use it.
The documentation says:
You must provide your registration calls ahead of wherever they will be needed, which includes two places:
- The
<PlasmicHost/>
(/plasmic-host
) page, for Plasmic Studio.- Wherever
<PlasmicComponent/>
is rendered, for your final pages.This is why we typically conventionally place them in
plasmic-init.ts
, and import this into both types of locations.
I can’t find the file plasmic-init.ts though.
Further down it says
Typically you should perform your registerations in your
plasmic-host.tsx
page.
… that’s what I tried:
import NextImage from "../components/NextImage";
registerComponent(NextImage, {
name: "NextImage",
props: {
src: "imageUrl",
alt: "string",
width: "number",
height: "number",
sizes: "string",
fill: "boolean",
priority: "boolean",
},
importPath: "./components/NextImage"
});
My NextImage looks like that:
// components/NextImage.tsx
import Image, { ImageProps } from "next/image";
import React from "react";
const NextImage = ({ src, alt, ...rest }: ImageProps) => {
return <Image alt={alt} src={src} {...rest} />;
};
export default NextImage;
Any suggestion on how I can resolve that error?
Do I need to actually import the component on every single page or can I somehow automate that, so that a designer can create pages / use custom components, without the need of adding import statements to each page.
Thanks!