Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. #143

Open
georgec-travellocal opened this issue Apr 23, 2023 · 8 comments

Comments

@georgec-travellocal
Copy link

For some reason when I use component in a package which I then do yarn link to another project, Next.js thinks Glider is an object not a react component.

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

The same occurs with react-slick

Any idea why this is?

I tried dynamic import with ssr false but it still fails after the client side is ready.

@kevinfarrugia
Copy link
Owner

Hi @georgec-travellocal .

I had created a demo repository using NextJS without any issue.

Can you take a look and see if there is anything different in the implementation? Heads up I might be using an older version of Next.

@georgec-travellocal
Copy link
Author

georgec-travellocal commented Apr 23, 2023 via email

@georgec-travellocal
Copy link
Author

georgec-travellocal commented Apr 23, 2023 via email

@kevinfarrugia
Copy link
Owner

Will update to Next 13 and take a look.

@kevinfarrugia
Copy link
Owner

kevinfarrugia commented Apr 24, 2023 via email

@georgec-travellocal
Copy link
Author

georgec-travellocal commented Apr 24, 2023 via email

@georgec-travellocal
Copy link
Author

georgec-travellocal commented Apr 24, 2023 via email

@coreydunkin
Copy link

coreydunkin commented Jun 15, 2023

Unsure if this is the same issue as yours @georgec-travellocal but had a similar issue where react-glider would work inside storybook but wouldn't work when exposed to a Nextjs 13 application. I kept getting the error "Cannot set properties of undefined (setting 'Glider')"

The workaround was to import the react-glider library inside a useEffect like so:

const [Glider, setGlider] = useState(null);
const gliderRef = useRef();

useEffect(() => {
import('react-glider').then((GliderModule) => {
setGlider(() => GliderModule.default);
});
}, []);

This removes the error after storybook is bundled and exposed to our NextJS app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants