kyranet / canvas-constructor

An ES6 utility for canvas with built-in functions and chained methods.
https://canvasconstructor.js.org
MIT License
116 stars 23 forks source link

TypeError: Canvas.resolveImage is not a function #356

Closed zyiang1928 closed 4 years ago

zyiang1928 commented 4 years ago

Anyone can help me? This is the code that I made

async function createCanvas() {
        const avatar = await Canvas.resolveImage(message.author.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 }));

        return new Canvas(1400, 1400)
            .setShadowColor("rgba(22, 22, 22, 0.3)")
            .setShadowOffsetY(5)
            .setShadowBlur(10)
            .printImage(avatar, 0, 0, 1400, 1400)
            .toBufferAsync()
     }

     message.channel.send(`**Avatar's for ${message.author.tag}**`, {
       files: [{
          attachment: await createCanvas(),
          name: "avatar.png"
       }]
     });
kyranet commented 4 years ago

What is the environment (browser, node.js) and which module definition are you using (UMD, AMD, requirejs, CommonJS, or ESM)?

And not less importantly, what's Canvas defined as, and what is your canvas-constructor version?

kyranet commented 4 years ago

Actually, reading your code, you're using discord.js, so you're 99.99% likely to be using Node.js with CJS.

I also see that Canvas is defined as the library's class, not the library's exports.

resolveImage is not a static method on Canvas, it's a separate export. To fix this, you need to do this:

const { Canvas, resolveImage } = require('canvas-constructor');
zyiang1928 commented 4 years ago

Oh okay thanks