microlinkhq / microlinkhq/react-json-view

"Element type is invalid" with vite 8

Open
#146 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
417
Forks
68
Avg merge
4h 22m
Merged PRs (30d)
8

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported React error with Vite 8 and the documented default import, then inspect the package's published export shape and build entry points. Done means the normal import resolves to a renderable component without the namespace-normalization workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.