Skip to content

Commit

Permalink
fix: dynamic import of esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Nov 17, 2023
1 parent 78ce657 commit 92d09f7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs'
import path from 'path'
import {StringDecoder} from 'string_decoder'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
import grayMatter from 'gray-matter'
import * as esbuild from 'esbuild'
import {NodeResolvePlugin} from '@esbuild-plugins/node-resolve'
Expand Down Expand Up @@ -38,8 +37,15 @@ async function bundleMDX({

// @mdx-js/esbuild is a native ESM, and we're running in a CJS context. This is the
// only way to import ESM within CJS
const [{default: mdxESBuild}, {default: remarkFrontmatter}] =
await Promise.all([import('@mdx-js/esbuild'), import('remark-frontmatter')])
const [
{default: mdxESBuild},
{default: remarkFrontmatter},
{default: remarkMdxFrontmatter},
] = await Promise.all([
import('@mdx-js/esbuild'),
import('remark-frontmatter'),
import('remark-mdx-frontmatter'),
])

let /** @type string */ code,
/** @type string */ entryPath,
Expand Down

0 comments on commit 92d09f7

Please sign in to comment.