How to convert 24bit PNG images to 8bit PNG images

I am currently using canvas library and I was able to successfully create 24bits images using the code below:

 const fs = require("fs");
    const { createCanvas, loadImage } = require("canvas");
    
    const canvas = createCanvas(3000, 3000); 
    const ctx = canvas.getContext("2d", {alpha: false});
    
    const loadMyImage = async (img) => {
        return new Promise(async (resolve) => {
            const image = await loadImage(`${img}`);
            resolve({ layer: img, loadedImage: image });
        });
    };
    
    const drawElement = (_renderObject) => {
        ctx.drawImage(_renderObject.loadedImage, 0, 0, 3000, 3000);
    };
    
    const saveImage = (img) => {
      fs.writeFileSync(
        `${img}.png`,
        canvas.toBuffer("image/png")
      );
    };
    
    const run = async () => {
                let loadedImg = loadMyImage('purple.png');
    
                //start drawing image
                await Promise.resolve(loadedImg).then((renderObject) => {
                    ctx.clearRect(0, 0, 3000, 3000);
                    drawElement(renderObject);
                    saveImage(1);
                });
    };
    
    (() => {
        run();
    })();

which works fine, but if I want to save images as 8bit PNG images, and change only this line to:

const ctx = canvas.getContext("2d", { pixelFormat: 'A8' });

I get only white images. What am I missing?