Closed souporserious closed 3 years ago
Looks like esbuild
needs to be told to build for Node.
You can set the platform using the esbuildOptions
parameter in bundleMdx
like so:
const { code, frontmatter } = await bundleMDX(contents, {
cwd: path.dirname(filePath),
esbuildOptions: (options) => {
options.platform = 'node'
return options
}
})
This got it working on your demo repository for me.
@Arcath that was it! 🎉 Thank you so much for looking into this, I appreciate your help!
mdx-bundler
version: 3.4.1node
version: 14.16.1npm
version: 6.14.12What you did:
Import a component that uses
styled-cmponents
:What happened:
Errors seemingly about
styled-components
, other third-party libraries all seem to work fine:Reproduction repository:
https://github.com/souporserious/mdx-bundler-and-styled-components
Problem description:
This is in the context of a NextJS app that reaches into another directory outside of the app and pulls all of the MDX files from it. This works without
styled-components
, but when it's added, I get the error above.This is my
getStaticProps
function responsible for fetching the MDX files: