Skip to content

"Element type is invalid" with vite 8 #146

@mbtools

Description

@mbtools

Our project moved to vite 8 and now we're getting react error 130:

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

This is with v1.31.12 and this import:

import ReactJson from '@microlink/react-json-view';

There seems to be an interop/export-shape problem with @microlink/react-json-view (UMD/CJS wrapping can make a “default import” resolve to a module object, and React then throws: “got: object”).

We worked around the issue by importing the module namespace and normalizing to the actual component (default or reactJsonView) before rendering:

import * as ReactJsonViewModule from '@microlink/react-json-view';

const ReactJson =
  ((ReactJsonViewModule as any).default ??
    (ReactJsonViewModule as any).reactJsonView ??
    ReactJsonViewModule) as React.ComponentType<any>;

After this, <ReactJson ... /> is always a real component at runtime.

Can this change be avoided? Is there something missing in this package?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions