kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

Version 10.0.0 fails with a [ERR_REQUIRE_ESM] error of the remark-mdx-frontmatter package. #217

Open dwjohnston opened 1 year ago

dwjohnston commented 1 year ago

Relevant code or config

Not applicable / see repro.

What you did:

I have working code mdx-bundler@9.2.1

When we upgrade to mdx-bundler@10.0.0 it errors.

What happened:


/Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/dist/index.js:11
var _remarkMdxFrontmatter = _interopRequireDefault(require("remark-mdx-frontmatter"));
                                                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/node_modules/remark-mdx-frontmatter/index.js from /Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/dist/index.js not supported.
Instead change the require of /Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/node_modules/remark-mdx-frontmatter/index.js in /Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/davidjohnston/git-workspace/example-remix-app/node_modules/mdx-bundler/dist/index.js:11:52)

Reproduction repository:

This commit has a basic Remix@1.9.3 application with mdx-bundler@9.2.1 working.

https://github.com/dwjohnston/example-remix-app/commit/193bd84e03cb7d3ebda0071851970b722b1f1c10

Run

npm i 
npm run dev

Navigate to any of the links to see some MDX being rendered fine.

This commit https://github.com/dwjohnston/example-remix-app/commit/359efc5fb9b387cd8b51d0d02af457409470ae86

Just upgrades mdx-bundler to 10.0.0.

When we run npm run dev we now get the [ERR_REQUIRE_ESM].

Problem description:

The problem appears to be that remark-mdx-frontmatter@4.0.0 publishes its packages as an ESM module and mdx-bundler@10 still requires this.

Suggested solution:

Not sure. Is this actually a bug with remark-mdx-frontmatter@4.0.0?

Workaround

Downgrade to 9.2.1

CottonCandyZ commented 1 year ago

10.0.1 fix it. https://github.com/kentcdodds/mdx-bundler/commit/92d09f7b29378524a8aa7f055bf81a2f624fc586