Receiving an error when trying to import the 'marked' module into an Angular project

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!

Answer №1

Encountering a similar issue occurred to me after installing marked and @types/marked with the most recent versions in my Angular 15 project.

To resolve this, I found that downgrading the versions as shown below worked for me

"ngx-markdown": "^15.1.2",
"marked": "^4.3.0",
"@types/marked": "^4.3.0",

Following this guide provided by , I was able to successfully resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Javascript scoping issue with a function that generates and returns other functions

I am facing an issue with my function where I keep getting 2 in the alert message every time. It seems like a variable scope problem, but I haven't been able to resolve it yet. var someObj = {"a" : 1, "b" : 2}; function retrieveData(obj){ var func ...

Issue with Mongoose schema: Unable to access the property 'password' as it is undefined

I recently attempted to implement passport local authentication based on a tutorial I found. Although everything appeared to be working correctly, I encountered an error when making a request using Postman: [nodemon] 1.18.11 [nodemon] to restart at any ti ...

Unraveling the Mystery: How Angular Handles Propagation of Color CSS Property Settings to Nested Components

Angular's style scope and inheritance are detailed in the guide: The styles defined in @Component metadata only affect the template of that specific component. They do not get passed down to any nested components or projected content. To propagate ...

Invoking a JavaScript function to retrieve an array of integers from a C# method for organizing columns in datatables.net

I have to admit that my JavaScript skills are not very strong. Currently, I am working on creating a table using datatables.net. The table is being populated by calling a generic handler, which in turn fetches data from the database using C#. This functio ...

Chartist JS: line graph dipping beneath the X-axis

I am currently using the Chartist JS jQuery plugin and encountering an issue where one of the functions is extending below the x-axis even though it does not have any negative points. Is there a way to resolve this issue? Please refer to the image for bet ...

I am receiving a success message from webpack indicating that the compilation was successful, but I am encountering a blank page in the

My app.js looks like this: import Home from "./pages/home/Home"; import Login from "./pages/login/Login"; import Profile from "./pages/profile/Profile"; import Register from "./pages/register/Register"; import { Brow ...

An exploration of navigating through a generic interface in Angular

I've recently started exploring Angular and I'm trying to incorporate a generic interface to reuse pagination models from different sources. Let me share some code examples to clarify. export interface IUser{ id: string; name: string; email: stri ...

An error has occurred in Typescript stating that there is no overload that matches the call for AnyStyledComponent since the update to nextjs

Upgraded to the latest version of nextjs, 13.3.1, and encountered an error in the IDE related to a styled component: Received error TS2769 after the upgrade: No overload matches this call. Overload 1 of 2, '(component: AnyStyledComponent): ThemedSty ...

Angular MistakeORAngular Error

Every time I refresh the page, I encounter an error in my code while attempting to display a newly edited and saved text. I've initialized the variable, made the access variable public, but it still doesn't work. Can someone point out what I migh ...

I have decided to integrate Laravel with Vite for building CSS and JS. However, when I attempted to run `npm run dev`, it appeared to execute but was accompanied by an error in the background that

Hi there, I'm new to Laravel and I've created a small app that primarily uses CSS and JS scripts. Everything was working fine in my development environment, so I decided to push it to a production server. However, after installation, my code does ...

Tips for creating a click event for a ViewChild element reference in Angular 8

Having trouble getting the click event to work for an element reference in typescript. Can anyone provide guidance on how to properly write a click event for an element reference? app.component.ts: @ViewChild('testElem') el:ElementRef; @Vie ...

Angular is programmed to detect any alterations

Upon detecting changes, the NgOnChanges function triggers an infinite service call to update the table, a situation that currently perplexes me. Any assistance on this matter would be greatly appreciated. Many thanks. The TableMultiSortComponent functions ...

jQuery sidebar with a fixed position

Is there a way to implement a sidebar menu feature using jQuery that reappears on the left as the user scrolls down the page? You can see an example sidebar menu here. ...

Generate a text string by choosing options from a form

Greetings! I have a form for creating a file, where the file name is determined by user selections. It's similar to "display text as you type" mentioned here, but my form includes radio buttons in addition to a textbox. For example: Textbox: "Name gi ...

The PHP code encountered a syntax error due to an unexpected $EOF on the final empty line

I've been tasked with maintaining an old website that went offline due to script errors. I managed to resolve most of the issues in the script, but there's one error that's giving me trouble. The site is showing a syntax error that says "une ...

Verify if the contract address corresponds to a token and retrieve the token details, such as its symbol

Can I use web3 to retrieve token information such as symbol and total supply similar to the etherscan API pro endpoint tokeninformation by providing the contract address? I'm interested in determining whether the addresses I collect are tokens or reg ...

Is it necessary to store tokens in cookies, local storage, or sessions?

I am currently utilizing React SPA, Express, Express-session, Passport, and JWT. I find myself puzzled by the various client-side storage options available for storing tokens: Cookies, Session, and JWT/Passport. Is it necessary to store tokens in cookies, ...

Implementing Angular Server-Side Rendering (SSR) with .Net Core - enhancing performance by including Cache-Control

In my current project, I am dealing with two types of pages: Angular SSR pages and MVC pages. I am looking to implement a Cache-Control header for only the Angular SSR pages, as they are static pages. Is there a way to achieve this specific caching strate ...

Disappear gradually within the click event function

I have a coding dilemma that I can't seem to solve. My code displays a question when clicked and also shows the answer for a set period of time. Everything works perfectly fine without the fadeOut function in the code. However, as soon as I add the fa ...

Using a promise inside an Angular custom filter

I am attempting to implement a filter that will provide either a success or error response from the ret() function. The current code is returning {}, which I believe is its promise. .filter('postcode', ['$cordovaSQLite', '$q' ...