Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
khusamov opened this issue Jul 11, 2019 · 11 comments
Closed

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

khusamov opened this issue Jul 11, 2019 · 11 comments
Assignees
Labels

Comments

@khusamov
Copy link

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
Copy link
Collaborator

Could you please test, if it works with:

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

@nagaozen nagaozen self-assigned this Jul 11, 2019
@nagaozen
Copy link
Collaborator

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
Copy link
Author

khusamov commented Jul 15, 2019

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

I do not understand where to insert this code.

@amxmln
Copy link

amxmln commented Jul 16, 2019

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
Copy link

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

@nagaozen
Copy link
Collaborator

.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
Copy link
Contributor

rivy commented Aug 10, 2019

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 <npmjs.com>. That makes it harder to debug/trace the code for the npmjs version.

@manastalukdar
Copy link

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
Copy link

axe-me commented Sep 18, 2019

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

@nagaozen
Copy link
Collaborator

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

  • dist/markdownItAnchor.js, specified as main in package.json. This is the default, CJS compatible format. It can be used as var md = require('markdown-it-anchor'). It can be tested at https://npm.runkit.com/markdown-it-anchor
  • dist/markdownItAnchor.mjs, specified as module in package.json. This version is made for modern ES6 environments. Its made to make many modern optimized builds possible, like using tree-shaking. You have to use/configure your bundler for this to work. In case you don't have a deep knowledge about your stack, its easy to find out by experimentation: if you are using import markdownItAnchor from markdown-it-anchor you are using ES6 syntax, that command is equivalent to const markdownItAnchor = require('markdown-it-anchor').default.
  • dist/markdownItAnchor.umd.js, specified as unpkg in package.json. This version is made for the browser. It exposes the library as window.markdownItAnchor.

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
Copy link

inix commented Apr 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants