Skip to content

React.lazy: Not recognizing named modules resolved through .then() #13962

Closed
@third774

Description

@third774

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Named components that have been extracted in a .then() call are not being recognized.

const NamedExport = React.lazy(() =>
  import("./NamedExport")
    .then(module => module.NamedExport)
    .then(component => {
      console.log(component)
      return component
    })
)

The code above is generating the error below despite the fact that the named export gets logged to the console correctly.

Invariant Violation
Element type is invalid. Received a promise that resolves to: undefined. Promise elements must resolve to a class or function.

Link to codesandbox example

What is the expected behavior?

This should render the component correctly

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

react 16.6.0
react-dom 16.6.0

MacOS 10.14 Version 69.0.3497.100

React.lazy was not in previous versions of React

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