Skip to content

ESM import issue causing: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. #115

@mo

Description

@mo

I have a project where I have used react-linkify successfully for several years. I'm currently upgrading this project to ESM (i.e. I'm putting "type": "module" into my own package.json file). I got most things in my app to work again using ESM but whenevert I open a page that renders a react linkify component I get this error:

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

I use the library like this:

import Linkify from 'react-linkify'
...
<Linkify>{comment}</Linkify>

If I print the Linkify like this: console.log('Linkify=', Linkify) it looks like this in the devtools:
image

I just to see if worked, I change the usage temporarily into <Linkify.default>{comment}</Linkify.default> and then it works.

However, Linkify.default is ugly... any ideas isn't my import working normally? Is it some kind of ESM/CJS interop layer used in react-linkify that is getting it the way here?

Does react-linkify support being imported in ESM projects?

Note: many other libraries can be imported just fine, like for example:
@stripe/react-stripe-js, @sentry/browser, @stripe/stripe-js/pure.js, react-router, react

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions