mdx-bundler
mdx-bundler copied to clipboard
Error: Cannot find module 'esbuild'
-
mdx-bundler
version: 6.0.1 -
node
version: 14.17.1 -
npm
version: 6.14.13
This is my config file - mdx.ts
import { bundleMDX } from "mdx-bundler";
import path from "path";
export const prepareMDX = async () => {
if (process.platform === "win32") {
process.env.ESBUILD_BINARY_PATH = path.join(
process.cwd(),
"node_modules",
"esbuild",
"esbuild.exe"
);
} else {
process.env.ESBUILD_BINARY_PATH = path.join(
process.cwd(),
"node_modules",
"esbuild",
"bin",
"esbuild"
);
}
const mdxSource = `
---
title: Example Post
published: 2021-02-13
description: This is some description
---
# Wahoo
`.trim();
const { code, frontmatter } = await bundleMDX(mdxSource);
return { code, frontmatter };
};
This is my page file - blog.tsx
import Layout from "@/components/Layout";
import { prepareMDX } from "@/lib/mdx";
import { getMDXComponent } from "mdx-bundler/client";
import { useMemo } from "react";
export default function blog({
code,
frontmatter
}: {
code: any;
frontmatter: any;
}) {
const Component = useMemo(() => getMDXComponent(code), [code]);
return (
<Layout>
<h2>{frontmatter.title}</h2>
<p>{frontmatter.description}</p>
<Component />
</Layout>
);
}
export async function getStaticProps() {
const { code, frontmatter } = await prepareMDX();
return { props: { code, frontmatter } };
}
Now I'm getting this error
Even though I see esbuild package in node_modules but still this error is shown.. why? how to solve it ?
I think you may forget to install esbuild as your dependency. Try installing using npm i esbuild
and try again. :)
I think you may forget to install esbuild as your dependency. Try installing using
npm i esbuild
and try again. :)
I did but still it isn't working
Which version of esbuild are you using?
Which version of esbuild are you using?
0.12.22
I'm having the exact same issue when using the remix-run's blues stack. But, it works just fine with remix-run's indie stack.