Word document is not created in Nodejs?

I am trying to take screenshot of the URLs using puppeteer and save screenshots in Word document, but it is not working giving me an error – Script encountered an error: TypeError: Cannot read properties of undefined (reading 'creator')

using docx.

code –

const puppeteer = require('puppeteer');
const { Document, Packer, Media, Paragraph, TextRun } = require('docx');
const fs = require('fs-extra');

const urls = [

async function captureScreenshots() {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  for (let i = 0; i < urls.length; i++) {
    const url = urls[i];
    await page.goto(url);
    await page.screenshot({ path: `screenshot${i}.png` });

  await browser.close();

async function createWordDocument() {
  const doc = new Document();
  const paragraph = new Paragraph();

  for (let i = 0; i < urls.length; i++) {
    const imagePath = `screenshot${i}.png`;
    const imageBuffer = fs.readFileSync(imagePath);
    const image = Media.addImage(doc, imageBuffer, 400, 300);
    paragraph.addRun(new TextRun().addImage(image));


  const packer = new Packer();
  const buffer = await packer.toBuffer(doc);
  fs.writeFileSync('output.docx', buffer);

  console.log('Word document created successfully!');

async function runScript() {
  try {
    await captureScreenshots();
    const doc = new Document();  
    await createWordDocument();
  } catch (error) {
    console.error('Script encountered an error:', error);


for testing pourpose as I have check, screenshot is captured and saved in the directory too, but word document is not creating and saving the screenshot in it.