mdx-bundler icon indicating copy to clipboard operation
mdx-bundler copied to clipboard

Error: Cannot find module 'esbuild'

Open swarup4741 opened this issue 3 years ago • 5 comments

  • 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

mdx-bundler

Even though I see esbuild package in node_modules but still this error is shown.. why? how to solve it ?

swarup4741 avatar Aug 22 '21 12:08 swarup4741

I think you may forget to install esbuild as your dependency. Try installing using npm i esbuild and try again. :)

muthhukumar avatar Aug 23 '21 01:08 muthhukumar

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

swarup4741 avatar Aug 23 '21 06:08 swarup4741

Which version of esbuild are you using?

Arcath avatar Aug 27 '21 13:08 Arcath

Which version of esbuild are you using?

0.12.22

swarup4741 avatar Aug 27 '21 15:08 swarup4741

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.

SangeetAgarwal avatar Jun 29 '23 21:06 SangeetAgarwal