Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Error: plugin.apply is not a function #1

Closed
zeroby0 opened this issue Aug 14, 2021 · 3 comments
Closed

Error: plugin.apply is not a function #1

zeroby0 opened this issue Aug 14, 2021 · 3 comments

Comments

@zeroby0
Copy link

zeroby0 commented Aug 14, 2021

Thanks for the plugin! :D

markdownIt().use(plugin, ...) calls plugin.apply(). But since this plugin doesn't define an apply function, an error is raised. @types/markdown-it doesn't seem to define is it either.

https://github.com/markdown-it/markdown-it/blob/6e2de08a0b03d3d0dcc524b89710ce05f83a0283/lib/index.js#L495-L499

Reproducing:
https://glitch.com/edit/#!/festive-orange-event?path=server.js%3A1%3A0

const markdownIt = require('markdown-it')
const mdShiki = require('markdown-it-shiki')

const mdlib = markdownIt()
        .use(mdShiki, {
            theme: 'nord'
        })

or

import MarkdownIt from 'markdown-it'
import Shiki from 'markdown-it-shiki'

const md = MarkdownIt()

md.use(Shiki, {
  theme: 'nord'
})

Error text:

/home/aravind/src/avoggu.com/node_modules/markdown-it/lib/index.js:497
  plugin.apply(plugin, args);
         ^

TypeError: plugin.apply is not a function
    at MarkdownIt.use (/home/aravind/src/avoggu.com/node_modules/markdown-it/lib/index.js:497:10)
    at file:///home/aravind/src/avoggu.com/ind.mjs:6:4
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
    at async handleMainPromise (node:internal/modules/run_main:63:12)
@antfu
Copy link
Owner

antfu commented Aug 14, 2021

I believe apply is from the function's prototype. While we did expose an function for it, try

const mdShiki = require('markdown-it-shiki').default

@zeroby0
Copy link
Author

zeroby0 commented Aug 14, 2021

Ooh that works! Thank you so much! I thought markdown-it changed, and the plugin would need a re-write 😂

Smart thinking, exposing the prototype! Can we add it to the Readme? Perhaps in an FAQs section?

@zeroby0 zeroby0 closed this as completed Aug 14, 2021
@antfu
Copy link
Owner

antfu commented Aug 14, 2021

The default is mostly because of the ESM/CJS converting. rollup/rollup#1961 (comment)

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

No branches or pull requests

2 participants