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

Esbuild Errors: When following the Getting Started

Open hsjobeki opened this issue 1 year ago • 5 comments

I really liked the idea to generate plain md from the semantic suggaring of mdx.

But unfortunately when following the tutorial of your readme the following errors do occour; preventing me from using it:

  1. ✘ [ERROR] Expected value for define "process.env.NODE_ENV" to be a string, got undefined instead
  2. ✘ [ERROR] The working directory "." is not an absolute path

I resolved the first error by simply setting export NODE_ENV=="production" But then the second error arises and i don't understand how to fix that. (Both come from esbuild it seems)

Steps to reproduce

1

mkdir test
npm init -y

# change type="module" in package.json

2

follow the steps from your readme

creating:

README.mdx

import { name, description } from "./package.json";

# {name}

{description}

# Install

<pre>
    <code className="language-bash">yarn add {name}</code>
</pre>

index.js

import { writeFile } from "fs/promises";
import { mdxToMd } from "mdx-to-md";

const markdown = await mdxToMd("README.mdx");
const banner = `This README was auto-generated using "yarn build:readme"`;
const readme = `<!--- ${banner} --> \n\n ${markdown}`;

await writeFile("README.md", readme);

console.log("📝 Converted README.mdx -> README.md");

3

node index.js

Complete error:

✘ [ERROR] The working directory "." is not an absolute path

/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1649
  let error = new Error(text);
              ^

Error: Build failed with 1 error:
error: The working directory "." is not an absolute path
    at failureErrorWithLog (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1649:15)
    at /home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1058:25
    at runOnEndCallbacks (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1484:45)
    at buildResponseToResult (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1056:7)
    at /home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:1085:16
    at responseCallbacks.<computed> (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:703:9)
    at handleIncomingPacket (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:762:9)
    at Socket.readFromStdout (/home/johannes/git/secunet-design/test/node_modules/esbuild/lib/main.js:679:7)
    at Socket.emit (node:events:512:28)
    at addChunk (node:internal/streams/readable:343:12) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

hsjobeki avatar Aug 29 '23 14:08 hsjobeki

I'm facing this error too

Senbonzakura1234 avatar Sep 30 '23 07:09 Senbonzakura1234

Same here

erfanmola avatar Oct 06 '23 00:10 erfanmola

Sorry, I've been super busy and haven't had time for this, happy to accept a PR!

souporserious avatar Oct 06 '23 00:10 souporserious

same here too

@souporserious if you create an issue about the problem how to solve it I can work on it

berkingurcan avatar Oct 14 '23 08:10 berkingurcan

I have solved by using:

const absolutePath = path.resolve("../files");

instead of

const basePath = "../files";

for the path of .mdx file.

berkingurcan avatar Oct 15 '23 15:10 berkingurcan