const marked = require('marked');
articleSchema.pre("validate", function(next) {
if (this.title){
this.slug = slugify(this.title, {lower: true, strict: true})
}
if(this.markdown){
this.sanitaizeHTML = marked(this.markdown);
}
next();
})
When I try to use marked module as a function I will return typeError
TypeError: marked is not a function at model. (C:\Users\araiz\OneDrive\Desktop\Test_001\models\article.js:42:30) at callMiddlewareFunction (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\kareem\index.js:628:27) at next (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\kareem\index.js:93:7) at Kareem.execPre (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\kareem\index.js:122:8) at Kareem.wrap (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\kareem\index.js:368:8) at model.$__validate (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\kareem\index.js:502:11) at C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\mongoose\lib\document.js:2576:10 at new Promise () at model.validate (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\mongoose\lib\document.js:2575:10) at model.validateBeforeSave (C:\Users\araiz\OneDrive\Desktop\Test_001\node_modules\mongoose\lib\plugins\validateBeforeSave.js:35:12)
The error you're getting is saying that
markedis not a function. This usually happens if the required module was not imported properly or the module itself is not exporting a function as expected.There could be a few reasons for this:
The
markedpackage is not installed. You can install it usingnpm install marked.You have a different version of the
markedpackage that might not be compatible. Try uninstalling and reinstalling the package:node_modulesfolder. Try deleting it and reinstalling your packages:marked.markedshould be a function if properly imported. It converts Markdown into HTML. Make sure you're using it correctly:Make sure to check if any of these solutions work for you. If not, please provide more information and we can find a more detailed solution.