uiwjs / uiwjs/react-md-editor

ESM package cannot be imported

Open
#466 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.9k
Forks
201
Avg merge
12m
Merged PRs (30d)
1

Description

Getting this error when I followed the docs:

./node_modules/@uiw/react-markdown-preview/lib/index.js:13:0
Module not found: ESM packages (react-markdown) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

Import trace for requested module:
./app/page.tsx

https://nextjs.org/docs/messages/module-not-found

Looks like the issue is uiwjs/react-md-editor is CommonJS but react-markdown is ESM, so this line in react-markdown-preview/lib/index.js causes the error above:

var _reactMarkdown = _interopRequireDefault(require("react-markdown"));

Here's what I have:

next.config.js

/** @type {import('next').NextConfig} */
require("dotenv").config();

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    appDir: true,
    esmExternals: true,
  },
};

const removeImports = require("next-remove-imports")();

module.exports = removeImports(nextConfig);

app/page.tsx:

"use client";

import "@uiw/react-md-editor/markdown-editor.css";
import "@uiw/react-markdown-preview/markdown.css";
import dynamic from "next/dynamic";
import { useState } from "react";

const MDEditor = dynamic(
  () => import("@uiw/react-md-editor").then((mod) => mod.default),
  { ssr: false }
);
const EditerMarkdown = dynamic(
  () =>
    import("@uiw/react-md-editor").then((mod) => {
      return mod.default.Markdown;
    }),
  { ssr: false }
);
const Markdown = dynamic(
  () => import("@uiw/react-markdown-preview").then((mod) => mod.default),
  { ssr: false }
);

function HomePage() {
  const [value, setValue] = useState("**Hello world!!!**");
  return (
    <div data-color-mode="dark">
      <MDEditor value={value} onChange={() => {}} />
      <div style={{ paddingTop: 50 }}>
        <Markdown source={value} />
      </div>
      <EditerMarkdown source={value} />
    </div>
  );
}

export default HomePage;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the error with app/page.tsx and next.config.js, then inspect the generated node_modules/@uiw/react-markdown-preview/lib/index.js entry and its react-markdown import. Done means the ESM package can be imported from the documented Next.js setup without the reported module-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.