Got an error by using pdf-dist library in NextJS

I got an error when I was trying to use a library called pdf-dist. Actually, it works fine, but it’s kinda annoying cause it makes the website reloads every time I save any files even though I just changed some CSS classes (cause I’m using TailwindCSS btw).

I’m using the library in my [email protected] project.
The code I’m using now:

import EntryModal from "@/components/EntryModal";
import { type MouseEvent, useEffect, useState } from "react";
import { useDropzone } from "react-dropzone";
import { useNovelConfig } from "@/hooks/useNovelConfig";
import { FaPlus } from "react-icons/fa6";
import { saveRag } from "@/utils/NovelService";
import * as pdfjsLib from "pdfjs-dist";

pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.4.168/pdf.worker.min.mjs";

const FileUploader = () => {
  const [chosenFile, setChosenFile] = useState<any>();
  const { acceptedFiles, getInputProps, getRootProps } = useDropzone({
    accept: {
      "text/plain": [".txt"],
      "application/pdf": [".pdf"],
    },
    maxFiles: 1,
  });

  useEffect(() => {
    if (!chosenFile) return;
    const saveFile = async () => {
      await saveRag({
        rag_content: chosenFile.text || "",
      });
    };
    saveFile();
  }, [chosenFile]);

  useEffect(() => {
    if (!acceptedFiles || acceptedFiles.length === 0) return;
    const file = acceptedFiles[0];
    if (file.type === "text/plain") {
      const reader = new FileReader();
      reader.onabort = () => console.log("file reading was aborted");
      reader.onerror = () => console.log("file reading has failed");
      reader.onload = async () => {
        const text = reader.result as string;
        setChosenFile({ ...file, text });
      };
      reader.readAsText(file);
    } else if (file.type === "application/pdf") {
      const reader = new FileReader();
      reader.onload = async () => {
        const typedArray = new Uint8Array(reader.result as ArrayBuffer);
        const pdf = await pdfjsLib.getDocument({ data: typedArray })?.promise;
        const textArray: string[] = [];
        for (let i = 1; i <= pdf.numPages; i++) {
          const page = await pdf.getPage(i);
          const textContent = await page.getTextContent();
          const strings = textContent.items.map((item: any) => item.str);
          textArray.push(strings.join(" "));
        }
        setChosenFile({ ...file, text: textArray.join("n") });
      };
      reader.readAsArrayBuffer(file);
    }
  }, [acceptedFiles]);

  return (
    <div className="flex h-[20%] w-full flex-col gap-1">
      <p className="text-lg font-bold">
        File Upload <span className="text-base text-slate-500">| txt/pdf</span>
      </p>
      <section {...getRootProps()} className="flex h-full w-full items-center justify-center rounded-xl bg-base-300 hover:cursor-pointer">
        <input {...getInputProps()} />
        <div className="flex flex-col text-center">
          <h3 className="text-base">Drag or select your file</h3>
          <p className="text-xs font-bold text-slate-200">File: {chosenFile ? chosenFile.path : "None"}</p>
        </div>
      </section>
    </div>
  );
};

The error details:

 ⨯ TypeError: Promise.withResolvers is not a function
    at __webpack_require__ (D:projectswebbasedclient.nextserverwebpack-runtime.js:33:42)
    at eval (./components/LorebookContent.tsx:15:68)
    at (ssr)/./components/LorebookContent.tsx (D:projectswebbasedclient.nextserverappnovelspage.js:206:1)
    at __webpack_require__ (D:projectswebbasedclient.nextserverwebpack-runtime.js:33:42)
    at eval (./components/SidebarWrapper.tsx:11:85)
    at (ssr)/./components/SidebarWrapper.tsx (D:projectswebbasedclient.nextserverappnovelspage.js:250:1)
    at __webpack_require__ (D:projectswebbasedclient.nextserverwebpack-runtime.js:33:42)
    at eval (./components/Sidebar.tsx:17:84)
    at (ssr)/./components/Sidebar.tsx (D:projectswebbasedclient.nextserverappnovelspage.js:239:1)      
    at Object.__webpack_require__ [as require] (D:projectswebbasedclient.nextserverwebpack-runtime.js:33:42)
digest: "4044564068"

I’ve tried to update my NPM version (cause it’s mentioned in ChatGPT). I’ve also tried to fix it by creating a function which returns a promise. But yeah, it’s still the same.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật