wooorm / xdm

Just a *really* good MDX compiler. No runtime. With esbuild, Rollup, and webpack plugins
http://wooorm.com/xdm/
MIT License
593 stars 18 forks source link

'mdast-util-mdx' is expected to be of type CommonJS, which does not support named exports. #72

Closed burhanuday closed 3 years ago

burhanuday commented 3 years ago

Initial checklist

Affected packages and versions: TODO

Steps to reproduce

SyntaxError: The requested module 'mdast-util-mdx' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from 'mdast-util-mdx';
const {fromMarkdown, toMarkdown} = pkg;
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:143:20)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
    at async bundleMDX (/home/burhanuday/burhan/projects/portfolio-and-blog/node_modules/mdx-bundler/dist/index.js:60:27)
    at async getFileBySlug (webpack-internal:///./lib/mdx.js:83:7)
    at async getStaticProps (webpack-internal:///./pages/blog/[...slug].js:42:16)
    at async renderToHTML (/home/burhanuday/burhan/projects/portfolio-and-blog/node_modules/next/dist/next-server/server/render.js:27:1780)
    at async /home/burhanuday/burhan/projects/portfolio-and-blog/node_modules/next/dist/next-server/server/next-server.js:112:97
    at async __wrapper (/home/burhanuday/burhan/projects/portfolio-and-blog/node_modules/next/dist/lib/coalesced-function.js:1:330)
    at async DevServer.renderToHTMLWithComponents (/home/burhanuday/burhan/projects/portfolio-and-blog/node_modules/next/dist/next-server/server/next-server.js:137:387)

Gets fixed by replacing in /lib/plugin/remark-mdx.js on line 14

import {fromMarkdown, toMarkdown} from 'mdast-util-mdx'

with

import pkg from 'mdast-util-mdx';
const {fromMarkdown, toMarkdown} = pkg;
wooorm commented 3 years ago

What build tools are you using?

burhanuday commented 3 years ago

https://github.com/timlrx/tailwind-nextjs-starter-blog I was trying to use this repo. the xdm package is a dependency of a dependency it's a NextJS project which uses Webpack 5 with the ESM module loader enabled

wooorm commented 3 years ago

This should be reported to Next.js (or perhaps can be configured there, I believe they have some settings for this).

xdm and its dependencies are fine!