I'm trying to convert HTML to Markdown in a Vue-application.
I'm trying to implement Turndown, but I'm getting the error, in the console:
TypeError: TurndownService is not a constructor
I'm using Webpack, to pile it. This is the vue-ponent I'm trying to use it in:
<script>
var TurndownService = require('turndown');
console.log( new TurndownService() ); // Returns 'undefined';
export default {
mounted() {
var turndownService = new TurndownService();
this.markdownContent = turndownService.turndown(
'<a href="">A link</a><p>Hello world</p>'
);
},
...
...
This is what it looks like in node_modules:
I've tried all kind of things, to solve it. Based on this, I tried
var TurndownService = require('turndown').TurndownService;
and
var TurndownService = require('turndown/dist/turndown').TurndownService;
... But no cigar. :-/
I'm trying to convert HTML to Markdown in a Vue-application.
I'm trying to implement Turndown, but I'm getting the error, in the console:
TypeError: TurndownService is not a constructor
I'm using Webpack, to pile it. This is the vue-ponent I'm trying to use it in:
<script>
var TurndownService = require('turndown');
console.log( new TurndownService() ); // Returns 'undefined';
export default {
mounted() {
var turndownService = new TurndownService();
this.markdownContent = turndownService.turndown(
'<a href="https://example">A link</a><p>Hello world</p>'
);
},
...
...
This is what it looks like in node_modules:
I've tried all kind of things, to solve it. Based on this, I tried
var TurndownService = require('turndown').TurndownService;
and
var TurndownService = require('turndown/dist/turndown').TurndownService;
... But no cigar. :-/
Share Improve this question asked Apr 10, 2019 at 20:39 ZethZeth 2,64010 gold badges61 silver badges121 bronze badges1 Answer
Reset to default 9Found your post while dealing with the same.
This fixed it for me:
const TurndownService = require('turndown').default;
After that, the regular instructions worked like a charm!