最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Turndown in Vue - TypeError: TurndownService is not a constructor - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

Found 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!

发布评论

评论列表(0)

  1. 暂无评论