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.3 #54

Closed manastalukdar closed 5 years ago

manastalukdar commented 5 years ago

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

TypeError: plugin.apply is not a function
    at MarkdownIt.push../node_modules/markdown-it/lib/index.js.MarkdownIt.use (vendors.._src_components_pages_blog__year__month__day__post.._src_components_pages_index.js:13325)
    at _callee$ (._src_components_pages_blog__year__month__day__post.js:553)
    at tryCatch (commons.app.js:6771)
    at Generator.invoke [as _invoke] (commons.app.js:6997)
    at Generator.prototype.<computed> [as next] (commons.app.js:6823)
    at asyncGeneratorStep (vendors.app.js:31)
    at _next (vendors.app.js:53)
    at vendors.app.js:60
    at new Promise (<anonymous>)
    at vendors.app.js:49

Reproducible using this repo.

nagaozen commented 5 years ago

Should be fixed in 5.2.4. Could you please confirm?

manastalukdar commented 5 years ago

Unfortunately same issue manifests with 5.2.4.

utahka commented 5 years ago

I have similar issue with 5.2.4

I am using this plugin with @nuxtjs/markdownit, and get following error.

TypeError: plugin.apply is not a function
    at MarkdownIt.push../node_modules/markdown-it/lib/index.js.MarkdownIt.use (vendors.app.js:3597)
    at app.js:2322
    at _callee2$ (app.js:2224)
    at tryCatch (commons.app.js:6088)
    at Generator.invoke [as _invoke] (commons.app.js:6322)
    at Generator.prototype.<computed> [as next] (commons.app.js:6140)
    at asyncGeneratorStep (commons.app.js:31)
    at _next (commons.app.js:53)
nagaozen commented 5 years ago

@manastalukdar are you also using @nuxtjs/markdownit? Could you please check if it works with the original source? https://www.npmjs.com/package/markdown-it

manastalukdar commented 5 years ago

@nagaozen Yes, I am also using @nuxtjs/markdownit. And the same problem persists even with the new version.

chris-dura commented 5 years ago

I get this error as well for using markdown-it in a Vue app.

nagaozen commented 5 years ago

This stack is really complicated. I couldn't reproduce the problem. I got:

[nagaozen@optiplex3020 website]$ npm run nuxt-dev

> manas.talukdar.personal.website@1.0.0 nuxt-dev /run/media/nagaozen/OS/sandbox/manastalukdar.github.io/website
> nuxt

   ╭─────────────────────────────────────────────╮
   │                                             │
   │   Nuxt.js v2.8.0                            │
   │   Running in development mode (universal)   │
   │                                             │
   │   Listening on: http://localhost:3000/      │
   │                                             │
   ╰─────────────────────────────────────────────╯

ℹ Preparing project for development                                                                                                                   15:46:18
ℹ Initial build may take a while                                                                                                                      15:46:18
✔ Builder initialized                                                                                                                                 15:46:18
✔ Nuxt files generated                                                                                                                                15:46:19

✖ Client
  Compiled with some errors in 4.94s

● Server █████████████████████████ building (40%) 258/275 modules 17 active
 vuetify-loader › vue-loader › src/components/other/blog/single-post/comments.vue

 ERROR  Failed to compile with 1 errors                                                                                               friendly-errors 15:46:26

Module build failed (from ./node_modules/eslint-loader/index.js):                                                                     friendly-errors 15:46:26
Error: Cannot find module 'eslint/lib/formatters/stylish'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.module.exports (/run/media/nagaozen/OS/sandbox/manastalukdar.github.io/website/node_modules/eslint-loader/index.js:199:26)
                                                                                                                                      friendly-errors 15:46:26
You may use special comments to disable some warnings.                                                                                friendly-errors 15:46:26
Use // eslint-disable-next-line to ignore the next line.                                                                              friendly-errors 15:46:26
Use /* eslint-disable */ to ignore all warnings in a file.                                                                            friendly-errors 15:46:26

✖ Client
  Compiled with some errors in 4.94s

✔ Server
  Compiled successfully in 22.00s

ℹ Waiting for file changes                                                                                                                            15:46:43
ℹ Memory usage: 253 MB (RSS: 456 MB)      
nagaozen commented 5 years ago

Couldn't get it to work, but I noticed in the packages.json that this stack is using an old version of the plugins. You may try:

npm update
npm i markdown-it-anchor@latest -S
npm i markdown-it-toc-done-right@latest -S

This should fix the issue

manastalukdar commented 5 years ago

@nagaozen The latest version of the plugins does not mitigate the problem, which is why I had to downgrade to older versions.

nagaozen commented 5 years ago

Could you please inform which version had it fixed?

manastalukdar commented 5 years ago

@nagaozen Versions below do not cause the issue. Newer versions do.

"markdown-it-anchor": "5.0.2" "markdown-it-toc-done-right": "3.0.1",

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)