hanford / remark-slate

Remark plugin to compile Markdown as a slate 0.50+ compatible object.
155 stars 42 forks source link

On NodeJS - TypeError: Cannot `process` without `Compiler` #63

Open janaka opened 2 years ago

janaka commented 2 years ago

Hi, Thanks for everybody's efforts on this project.

I've been having issues getting it to work on NodeJS and all things point to the issue being with remark-slate with Node. The same code worked fine in the browser within a React app. I want to use this on the backend to handle read/write from markdown persistence.

I've tried debugging myself but haven't made much progress. I've also tried different versions of dependencies with no luck.

Seems like somebody else has had issues trying to use for a similar use case. See thread here.

fwiw I seem to be making a bit more progress with remark-slate-transformer.

Any ideas?

Much appreciated.

My test code

  unified()
    .use(remarkParse)
    .use(remarkSlate)
    .process('[my link](https://github.com)', (err, file) => {
      if (err) throw err;
      if (!file) throw "file is undefined"
      console.log(file);
    });

The error thrown by Unified. node_modules/unified/lib/index.js:520 the assertCompiler function.

TypeError: Cannot `process` without `Compiler`

with ESM + Typescript

woodpeng commented 2 years ago

I uncounted the same err.

I import the remark-slate with: const slate = require('remark-slate');

Then resolve the error with:

unified()
    .use(remarkParse)
    .use(slate.default)
hanford commented 2 years ago

@woodpeng interesting, is this an issue with how I'm distributing the module? If so that sounds like an easy fix

woodpeng commented 2 years ago

Since my project using CommonJs instead of ESM, I have to use 'require' to import the module. I am not sure whether this change caused the err, then have to add the '.default' to make it work.

andrew-st-angelo-dockethq commented 2 years ago

I too am receiving the Cannot `process` without `Compiler`. I've imported remark-slate, as part of an ESM. And using the .default trick prevents the error from being thrown but my export remains in Markdown.

await unified().use(remarkParse).use(remarkSlate.default).process('[my link](https://github.com)');

Any thoughts?