souporserious / mdx-to-md

Convert MDX to Markdown.
51 stars 2 forks source link

Esbuild Errors: When following the Getting Started #4

Open hsjobeki opened 1 year ago

hsjobeki commented 1 year ago

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]
}
Senbonzakura1234 commented 11 months ago

I'm facing this error too

erfanmola commented 11 months ago

Same here

souporserious commented 11 months ago

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

berkingurcan commented 11 months ago

same here too

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

berkingurcan commented 11 months ago

I have solved by using:

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

instead of

const basePath = "../files";

for the path of .mdx file.