Skip to content

Bug: fails to compile on nextjs Client Component SSR - Error: Element type is invalid: expected a string #5823

@2wheeh

Description

@2wheeh

Lexical version: 0.14.3

Steps To Reproduce

  1. clone https://github.com/2wheeh/nextjs-lexical-build-error
  2. try build (or compile dynamic route pages by accessing localhost:3000/not-work/hi)

Link to code example: https://github.com/2wheeh/nextjs-lexical-build-error

The current behavior

Call apis or anything imported from Lexical in ClientComponent (with 'use client' directive).
Rendering this component in nextjs server side fails.

// client-component.tsx
'use client';

import { COMMAND_PRIORITY_CRITICAL } from 'lexical'; // just a simple constant. 

export default function ClientComponent() {
  COMMAND_PRIORITY_CRITICAL;

  return <>hi</>;
}
// not-work/page.tsx
import ClientComponent from '../client-component';

export default function Page() {
  return <ClientComponent />;
}
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

build time: fails to generate static pages.

image

run time: fails to compile dynamic ssr pages.

image

Now It only works with dynamic imports with no ssr.

// work/page.tsx
import dynamic from 'next/dynamic';

const ClientComponent = dynamic(() => import('../client-component'), { ssr: false });

export default function Page() {
  return <ClientComponent />;
}

The expected behavior

works well as it was til 0.14.2

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