Skip to content

Incorrect import with ESBuild bundling (must use <Editor.default ... />) #106

Open

Description

@Olliebrown

Current behaviour

When building with esbuild the default import is not a Component and fails to render (react crashes).

Note: This may be an issue with ESBuild and not with react-simple-code-editor but I am listing here so folks can find the workaround.

Expected behaviour

You can import the default export as Editor and render it like a component as <Editor ... />

Workaround

It seems that ESBuild leaves the actual component buried under one more 'default' export so just render with <Editor.default ... /> to workaround the problem.

Code sample

The demo/example code will show this as long as you are trying to bundle with ESBuild

Your Environment

software version
react-simple-code-editor 0.13.1
react 18.1
npm 8.11
node 16.15.1
esbuild 0.14.36

Activity

  1. Yonom commented on Jul 15, 2024

    @Yonom

    what the hell, thanks a lot!

  2. citelao commented on Mar 29, 2025

    @citelao

    I had this issue trying to render the component in Astro. I'd get this error:

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

    Initially, I addressed it by only rendering the component on the client (on my host .astro component: client:only="react"). But I wanted to use client:visible. Unfortunately, the suggested workaround didn't work (since astro dev uses a different renderer than astro build && astro host), so I had to be more flexible:

    import SimpleEditorRaw from "react-simple-code-editor";
    
    let SimpleEditor: typeof SimpleEditorRaw = null!;
    if ((SimpleEditorRaw as any).hasOwnProperty("default")) {
        SimpleEditor = (SimpleEditorRaw as any).default;
    } else {
        SimpleEditor = SimpleEditorRaw;
    }
    
    // ...
    <SimpleEditor />
    // ...

    This works correctly for astro dev and astro build && astro host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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