Working on a project with Angular 15, I recently added marked to transform MarkDown text to HTML using an Angular pipe. However, no matter how I import it, I can't seem to get it working and keep encountering errors.
I followed these steps:
npm i marked
and then:
npm i --save-dev @types/marked
Next, I created this pipe:
import { Pipe, PipeTransform } from '@angular/core';
// import { marked } from 'marked';
import * as marked from 'marked';
@Pipe({
name: 'mdToHtml'
})
export class MdToHtmlPipe implements PipeTransform {
transform(value: any): any {
if (value && value.length > 0) {
return marked.marked(value);
}
return value;
}
}
I attempted importing marked using import { marked } from 'marked';
and
import * as marked from 'marked';
, but neither method seems to work.
The errors I encounter include:
Error: node_modules/marked/lib/marked.d.ts:613:5 - error TS1383: Only named exports may use 'export type'.
613 export type * from "MarkedOptions";
Additionally, the compilation fails when trying to run ng serve.
Any help would be greatly appreciated. Thank you!