oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.42k stars 2.78k forks source link

skia-canvas not working correctly #9915

Open emirsassan opened 7 months ago

emirsassan commented 7 months ago

What version of Bun is running?

1.1.0+5903a6141

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

import { SlashCommandBuilder } from "@discordjs/builders";
import { Client, CommandInteraction } from "discord.js";
import { Canvas, loadImage, loadFont } from "canvas-constructor/skia";
import { EconomyModel } from "../models/economy";
loadFont("PoppinsBold", "./fonts/Poppins-SemiBold.otf");
loadFont("Poppins", "./fonts/Poppins-Regular.otf");
loadFont("PoppinsMedium", "./fonts/Poppins-Medium.otf");
import {formatNumber} from "../utils/mathUtils";

export default {
  data: new SlashCommandBuilder()
    .setName("bakiye")
    .setDescription("Cüzdanını incele, bakiyeni gör."),
  run: async (client: Client, interaction: CommandInteraction) => {

    let economyData = await EconomyModel.findOne({ id: interaction.user.id });

    //@ts-ignore
    const numberWithCommas = formatNumber(economyData.cash);

    const nick = interaction.user.username;
    const canvas = new Canvas(343, 180);
    const kiremit = await loadImage(`./src/img/bakiye.png`);
    canvas.printImage(kiremit, 0, 0);
    canvas.setColor("#2AD100");
    canvas.setTextAlign("center")
    canvas.setTextFont("14px Poppins");
    canvas.printText(`▲ +$5534 (%32)`, 171, 147);
    canvas.setColor("#D9D9D9");
    canvas.setTextFont("39px PoppinsBold");
    canvas.printText(`$ ${numberWithCommas}`, 171, 91);

    const attachment = canvas.toBuffer("png");

    await interaction.reply({
      content: `> **Bakiye • [ ${nick} ] • <:wallet1:1224509010284118046>**`,
      files: [attachment],
    });
  },
};

or anything that uses skia-canvas for mine thats the thing

What is the expected behavior?

load command and send a image rendered with skia-canvas to channel but bot ignores command since skia-canvas throws an error

What do you see instead?

image

Additional information

No response

zfedoran commented 7 months ago

Facing the same issue using Docker.

FROM oven/bun:latest

RUN apt-get update
RUN apt-get install -y -q --no-install-recommends libfontconfig1 
RUN bun install skia-canvas

...

Getting the following error

error: Cannot find module "./v6" from "/app/node_modules/skia-canvas/lib/index.js"

I suspect it has something to do with the install flows that skia-canvas expects here: https://github.com/samizdatco/skia-canvas/blob/main/package.json#L21-L22

dienstbereit commented 6 months ago

Is there an update here?

I have the same problem on an Ubuntu 20.04 with NGINX 1.18.0.

But...

On my local MacBook installation it runs without any problems.

I am at a loss 🤷‍♂️ Maybe the info that it runs on one system and not the other will help someone.

emirsassan commented 6 months ago

No update on my side, it still has the same problem, probably a problem with skia-canvas.

dienstbereit commented 6 months ago

No update on my side, it still has the same problem, probably a problem with skia-canvas.

Thank you for your update. I have swapped skia for @napi-rs/canvas. That seems to work for now.