Skip to content

@react-email/render does not support dynamic import in next js #619

@laubonghaudoi

Description

@laubonghaudoi

Describe the Bug

I tried to dynamically import the render function from @react-email/render package with the codes below in NextJS 13.2:

import dynamic from "next/dynamic";

const render = dynamic(() =>
  import("@react-email/render").then((mod) => mod.render)
);

However, I got errors like this

Argument of type '() => Promise<(component: ReactElement<any, string | JSXElementConstructor<any>>, options?: Options | undefined) => string>' is not assignable to parameter of type 'DynamicOptions<ReactElement<any, string | JSXElementConstructor<any>>> | Loader<ReactElement<any, string | JSXElementConstructor<any>>>'.
  Type '() => Promise<(component: ReactElement<any, string | JSXElementConstructor<any>>, options?: Options | undefined) => string>' is not assignable to type '() => LoaderComponent<ReactElement<any, string | JSXElementConstructor<any>>>'.
    Type 'Promise<(component: ReactElement<any, string | JSXElementConstructor<any>>, options?: Options | undefined) => string>' is not assignable to type 'LoaderComponent<ReactElement<any, string | JSXElementConstructor<any>>>'.
      Type '(component: ReactElement<any, string | JSXElementConstructor<any>>, options?: Options | undefined) => string' is not assignable to type 'ComponentType<ReactElement<any, string | JSXElementConstructor<any>>> | ComponentModule<ReactElement<any, string | JSXElementConstructor<any>>>'.
        Type '(component: ReactElement<any, string | JSXElementConstructor<any>>, options?: Options | undefined) => string' is not assignable to type 'FunctionComponent<ReactElement<any, string | JSXElementConstructor<any>>>'.
          Type 'string' is not assignable to type 'ReactElement<any, any>'.ts(2345)
(alias) const render: (component: React.ReactElement, options?: Options) => string
export render

Which package is affected (leave empty if unsure)

@react-email/render

Link to the code that reproduces this issue

see below

To Reproduce

In a next js 13 project, use the codes below to dynamically import the render function.

import dynamic from "next/dynamic";

const render = dynamic(() =>
  import("@react-email/render").then((mod) => mod.render)
);

Expected Behavior

Render function should be imported with no error.

What's your node version? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions