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

Error TypeError: plugin.apply is not a function #402

Closed
nhoizey opened this issue Mar 19, 2023 · 10 comments
Closed

Error TypeError: plugin.apply is not a function #402

nhoizey opened this issue Mar 19, 2023 · 10 comments

Comments

@nhoizey
Copy link

nhoizey commented Mar 19, 2023

I'm trying to use markdown-it-image-size 13.1.1 with markdown-it 13.0.1 and I get this error, whatever code I write: TypeError: plugin.apply is not a function

This is a simple example:

const MarkdownIt = require("markdown-it");
const MarkdownItImageSize = require("markdown-it-image-size");

const md = new MarkdownIt();
md.use(MarkdownItImageSize);

let result = md.render(`# markdown-it rulezz!

![](image.jpg)

`);

console.log(result);

Here's the error log:

node_modules/markdown-it/lib/index.js:497
  plugin.apply(plugin, args);
         ^

TypeError: plugin.apply is not a function
    at MarkdownIt.use (node_modules/markdown-it/lib/index.js:497:10)
    at Object.<anonymous> (index.js:5:4)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.12.1
@boyum
Copy link
Owner

boyum commented Mar 19, 2023

Thanks for creating the issue! I'll look into it as soon as I have some free time ✨

@nhoizey
Copy link
Author

nhoizey commented Mar 19, 2023

Thanks! 🙏

@boyum
Copy link
Owner

boyum commented Mar 24, 2023

I see that you have imported the default, however markdown-it-image-size only exports markdownItImageSize.

This should work:

const MarkdownIt = require("markdown-it");
const { markdownItImageSize } = require("markdown-it-image-size");

const md = new MarkdownIt();
md.use(MarkdownItImageSize);

let result = md.render(`# markdown-it rulezz!

![](image.jpg)

`);

console.log(result);

Working example: https://runkit.com/embed/myowsfrf5mph

EDIT: Misclicked and closed the issue unwillingly.

@boyum boyum closed this as completed Mar 24, 2023
@boyum boyum reopened this Mar 24, 2023
@nhoizey
Copy link
Author

nhoizey commented Mar 24, 2023

@boyum I guess there's a typo in your code with a lowercase initial in markdownItImageSize.

But anyway, I get the same error with { MarkdownItImageSize } = require("markdown-it-image-size"); as I did without the curly braces.

@boyum
Copy link
Owner

boyum commented Mar 24, 2023

No, the exported function is named markdownItImageSize, not MarkdownItImageSize.

@nhoizey
Copy link
Author

nhoizey commented Mar 24, 2023

But then you use md.use(MarkdownItImageSize); with an uppercase M? 🤔

@nhoizey
Copy link
Author

nhoizey commented Mar 24, 2023

Ooooh, it works when I use lowercase m everywhere… sorry for not trying it first. 😞

@nhoizey nhoizey closed this as completed Mar 24, 2023
@boyum
Copy link
Owner

boyum commented Mar 24, 2023

Ah, sorry for updating only the import, not inside use. Great!

@dingshaohua-cn
Copy link

i use it in my react project created base on vite, vite just support esm

import {markdownItImageSize}  from 'markdown-it-image-size';
// console.log(111, markdownItImageSize);

const md = MarkdownIt({
  html: true,
  linkify: true,
  typographer: true,
}).use(markdownItImageSize);
/

and find this error

chunk-CEQRFMJQ.js?v=9d55e0d4:11 Module "util" has been externalized for browser compatibility. Cannot access "util.inherits" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
get @ browser-external:util:9
(anonymous) @ index.js:128
node_modules/markdown-it-image-size/dist/index.js @ index.js:134
__require @ chunk-CEQRFMJQ.js?v=9d55e0d4:11
(anonymous) @ index.js:1526
chunk-CEQRFMJQ.js?v=9d55e0d4:11 Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
get @ browser-external:events:9
node_modules/markdown-it-image-size/dist/index.js @ index.js:137
__require @ chunk-CEQRFMJQ.js?v=9d55e0d4:11
(anonymous) @ index.js:1526
index.js:147 Uncaught TypeError: Cannot read properties of undefined (reading 'call')
    at new Queue (index.js:147:16)
    at index.js:1321:17
    at node_modules/markdown-it-image-size/dist/index.js (index.js:1441:1)
    at __require (chunk-CEQRFMJQ.js?v=9d55e0d4:11:50)
    at index.js:1526:31

@boyum boyum mentioned this issue Dec 7, 2023
1 task
@boyum
Copy link
Owner

boyum commented Dec 7, 2023

@dingshaohua-cn Please continue this conversation in #416.

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

No branches or pull requests

3 participants