How to fix Sveltekit build issues

I built an API that uses the canvas module on the server using Sveltekit.
Everything was working properly when I was writing and testing the code.
However, when I perform npm run build, I get the following error message:

> [email protected] build
> vite build                 

vite v5.4.11 building SSR bundle for production...
✓ 194 modules transformed.
x Build failed in 4.78s
error during build:
[commonjs--resolver] ../../Common/node_modules/canvas/build/Release/canvas.node (1:2): Unexpected character '�' (Note that you need plugins to import files that are not JavaScript)
file: abc/Common/node_modules/canvas/lib/context2d.js:1:2

1: MZ�♥♦���@►☺♫▼�♫�     �!�☺L�!This program cannot be run in DOS mode.
     ^
2: $�������������
3: �����

    at getRollupError (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at ParseError.initialise (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/node-entry.js:13286:28)
    at convertNode (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/node-entry.js:14997:10)
    at convertProgram (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/node-entry.js:14240:12)
    at Module.setSource (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/node-entry.js:15983:24)
    at async ModuleLoader.addModuleSource (file:///abc/Projects/nudity_detector/node_modules/rollup/dist/es/shared/node-entry.js:19879:13)

I added

build: {
        rollupOptions: {
            external: [
                "canvas",
            ]
        }
    },

to the vite.config.ts file and tried to rebuild and now I’m getting this error:

> [email protected] build
> vite build

vite v5.4.11 building SSR bundle for production...
src/routes/api/nude/+server.ts (1:14): "RequestEvent" is not exported by "node_modules/@sveltejs/kit/src/exports/index.js", imported by "src/routes/api/nude/+server.ts".
✓ 463 modules transformed.
Generated an empty chunk: "entries/endpoints/api/nude/multipart/_server.ts".

node:internal/event_target:1100
  process.nextTick(() => { throw err; });
                           ^
ReferenceError [Error]: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'abcProjectsnudity_detectorpackage.json' contains "type": "module". To treat it as a CommonJS script, rename it to u
se the '.cjs' file extension.
    at file:///abc/Projects/nudity_detector/.svelte-kit/output/server/entries/endpoints/api/nude/_server.ts.js:268:61
    at file:///abc/Projects/nudity_detector/.svelte-kit/output/server/entries/endpoints/api/nude/_server.ts.js:425:3
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async analyse (file:///abc/Projects/nudity_detector/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:84:62)
    at async MessagePort.<anonymous> (file:///abc/Projects/nudity_detector/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

Node.js v20.12.2

I have not used __dirname in the project.
How do I fix these issues?

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