valeriangalliat / markdown-it-anchor

A markdown-it plugin that adds an `id` attribute to headings and optionally permalinks.
The Unlicense
292 stars 72 forks source link

TypeError: plugin.apply is not a function with v5.2.4 #55

Closed khusamov closed 5 years ago

khusamov commented 5 years ago

Running into "TypeError: plugin.apply is not a function" with version 5.2.4.

./node_modules/markdown-it/lib/index.js.MarkdownIt.use
./node_modules/markdown-it/lib/index.js:496
  493 |  **/
  494 | MarkdownIt.prototype.use = function (plugin /*, params, ... */) {
  495 |   var args = [ this ].concat(Array.prototype.slice.call(arguments, 1));
> 496 |   plugin.apply(plugin, args);
  497 |   return this;
  498 | };
  499 | 
nagaozen commented 5 years ago

Could you please test, if it works with:

.use(require('markdown-it-anchor').default)
nagaozen commented 5 years ago

This error seems to be reported before (#54) and is related to (#12). If the above suggestion works, we should search for a fix like

khusamov commented 5 years ago

.use(require('markdown-it-anchor').default)

I do not understand where to insert this code.

amxmln commented 5 years ago

I’m affected by this error as well after upgrading to the latest version. I can confirm that the workaround suggested by @nagaozen seems to fix it.

manastalukdar commented 5 years ago

The workaround does not work for me. Either for markdown-it-anchor or for markdown-it-toc-done-right.

nagaozen commented 5 years ago

.use(require('markdown-it-anchor').default)

I do not understand where to insert this code.

When using markdown-it-anchor, usually you are importing the packages either with import ... or require(...). We've encountered a bug before when babel was transpiling the code into something else and started using exports.default instead of the Node.js exports, so loading the package as require('markdown-it-anchor').default should fix the problem.

Just another note: In the past, this package required babel transpilation due to modern ES6+ features used in the source code, but with the latest versions it's not required anymore, just require as a ES5 dependency as shown here https://npm.runkit.com/markdown-it-toc-done-right.

rivy commented 5 years ago

I'm hitting the same problem after v5.1.0.

The workaround does work for v5.2.4.

But if it's not going to be fixed, I think you should deprecate the v5.x.x versions after v5.1.0 and update the semantic version to v6.x.x. At a minimum, I'd note the need at the top of the npmjs documentation for the time being...

Additionally, there are no version tags here after v5.1.0 despite several later released versions on . That makes it harder to debug/trace the code for the npmjs version.

manastalukdar commented 5 years ago

Fixed by including packages using the import statement:

import markdownItAnchor from 'markdown-it-anchor'
import markdownItTocDoneRight from 'markdown-it-toc-done-right'

const md = require('markdown-it')
    .use(markdownItAnchor, {
        permalink: true,
        permalinkBefore: true,
        permalinkSymbol: '' // §
      })
    .use(markdownItTocDoneRight)
axe-me commented 5 years ago

still doesn't work with nuxt @nuxtjs/markdownit module.

nagaozen commented 5 years ago

Since we migrated our project to microbundle, there are 3 flavours of production ready files built in the dist folder:

There are no breaking changes, in the version 5.x.x since the exactly same version of runkit.js is still working fine. Errors shown are usually downstream or problems with configuration.

inix commented 3 years ago

Fixed by including packages using the import statement:

import markdownItAnchor from 'markdown-it-anchor'
import markdownItTocDoneRight from 'markdown-it-toc-done-right'

const md = require('markdown-it')
    .use(markdownItAnchor, {
        permalink: true,
        permalinkBefore: true,
        permalinkSymbol: '' // §
      })
    .use(markdownItTocDoneRight)

This fix issue.