Skip to content

Error [ERR_REQUIRE_ESM]: require() of ES Module #216

@lhjeong60

Description

@lhjeong60

Hi, I m using Next.js v13 and I already use next-remove-imports, And I also check issue #184.
In my project, I have to render markdown in server side.

I got below Error when I import react-markdown-preview directly or dynamic import (next/dynamic) with ssr option as true.

error - Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/react-markdown/index.js from .../node_modules/@uiw/react-markdown-preview/lib/index.js not supported.

In my opinion, this error is caused by module between CommonJS and ES Module.
#184 and I both import out of browser which is electron, node.js, maybe they use CommonJS module System.
In node_modules/@uiw/react-markdown-preview/lib/index.js, some project was imported by CommonJS, but I Guess, they export ES module system only.

Now, I solve this problem by changing require() to (async () => await import())() in node_modules/@uiw/react-markdown-preview/lib/index.js
But I think this way is a bad idea.

Has anyone solved this problem?

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